AVR Example T1 counter
Zo stránky SensorWiki
Tento program pouzije D5 (arduino) ako pocitadlo. Mozne pripojit tlacitko, alebo 555 a pocitat pocet impulzov.
Vstavany terminal Arduina nema formatovanie, takze treba pouzit iny terminal aby sa to pekne vypisovalo:
#define SWITCH 5 // select the pin for Switch
void setup()
{
pinMode(SWITCH, INPUT); // this pin is an INPUT
TCNT1 = 0x00;
TCCR1B = 0x07; // timer1 clock = external clock source on pin T1, rising edge
Serial.begin(9600);
Serial.println("Button test:");
}
void loop() // endless loop
{
Serial.print("Input D5 = ");
Serial.print(digitalRead(SWITCH),BIN);
Serial.print(" TCNT1 = ");
Serial.print(TCNT1,DEC);
Serial.print('\r'); // nefunguje so vstavanym,
// ale je OK s putty terminalom
delay(250); // wait 1/4s for another
}