AVR Example T1 counter: Rozdiel medzi revíziami
Zo stránky SensorWiki
Bez shrnutí editace |
Bez shrnutí editace |
||
Riadok 10: | Riadok 10: | ||
void setup() | void setup() | ||
{ | { | ||
pinMode(SWITCH, INPUT); // this pin is an INPUT | pinMode(SWITCH, INPUT); // this pin is an INPUT | ||
TCNT1 = 0x00; | TCNT1 = 0x00; | ||
TCCR1B = 0x07; // timer1 clock = external clock source on pin T1, rising edge | TCCR1B = 0x07; // timer1 clock = external clock source on pin T1, rising edge | ||
Serial.begin(9600); | |||
Serial.println("Button test:"); | |||
} | } | ||
Verzia z 09:26, 13. október 2010
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
}