# define PIN 5
# define ALARM 7
void setup() {
TCCR1A = 0;
TCCR1B = (1 << CS12) | (1 << CS11); // | (1 << CS10);
TCCR1C = 0;
Serial.begin(115200);
Serial.println(" Hello Counter One World!\n");
pinMode(PIN, INPUT_PULLUP);
pinMode(ALARM, OUTPUT);
digitalWrite(ALARM, HIGH);
delay(500);
digitalWrite(ALARM, LOW);
}
unsigned int count;
void loop() {
while (digitalRead(PIN));
while (!digitalRead(PIN));
count++;
Serial.print(count);
Serial.print(" ");
int lo8 = TCNT1L; int hi8 = TCNT1H;
int theCount = (hi8 << 8 ) | lo8;
Serial.print(theCount);
Serial.println(" ");
if (theCount - count != 0) {
Serial.println("\nThat's All, Folks!\n");
digitalWrite(ALARM, HIGH);
for (; ; );
}
}
// real output - timer/counter 1 counts glitches from the pushbutton
// an unbounced input just increments both once per
/*
Hello Counter One World!
0 4
1 6
2 7
3 10
4 17
5 21
6 22
7 26
8 27
9 29
10 37
11 41
12 42
*/