#include <Wire.h>
void setup()
{
TCCR1A = 0b00000000; //TCCR1A bit 0, 1 and TCCR1B bit 3, 4 set timer mode
TCCR1B = 0b00001101; //Set mode to be clear on compare. set scaler to be clock/1024
OCR1A = 7811; //period = (OCR1A/B + 1)*scaler*62.5ns = 0.5s
TIMSK1 = 0b00000010; //enable timer counter
sei();
Wire.begin();
Serial.begin(9600);
}
void loop()
{
byte data;
Wire.requestFrom(0x20, 1); //request 1 byte from I2C expander
while(Wire.available()) {
data = Wire.read();
Serial.print("reader1 data ");
printBin(data);
Serial.println();
}
Wire.requestFrom(0x21, 1); //request 1 byte from I2C expander
while(Wire.available()) {
data = Wire.read();
Serial.print("reader2 data ");
printBin(data);
Serial.println();
}
delay(1000);
}
ISR(TIMER1_COMPA_vect){
PORTC ^= 0b00000001; //toggle pin 6(shift register clock)
}
void printBin(byte aByte) {
for (int8_t aBit = 7; aBit >= 0; aBit--)
Serial.write(bitRead(aByte, aBit) ? '1' : '0');
}
Johnson decade counter
reference:Johnson decade counter
No comments:
Post a Comment