AVR Example T1 counter: Rozdiel medzi revíziami
Zo stránky SensorWiki
Bez shrnutí editace |
Bez shrnutí editace |
||
Riadok 6: | Riadok 6: | ||
<source lang="c"> | <source lang="c"> | ||
#define SWITCH 5 | #define SWITCH 5 // select the pin for Switch | ||
void setup() | void setup() | ||
{ | { | ||
pinMode(SWITCH, INPUT); // this pin is an INPUT | pinMode(SWITCH, INPUT); // this pin is an INPUT | ||
TCNT1 = 0x00; // initialize (CLEAR)counter | |||
TCCR1B = 0x07; // | TCCR1B = 0x07; // T1 clk = external clock source on pin T1, rising edge | ||
Serial.begin(9600); | Serial.begin(9600); | ||
Riadok 24: | Riadok 24: | ||
Serial.print(" TCNT1 = "); | Serial.print(" TCNT1 = "); | ||
Serial.print(TCNT1,DEC); | Serial.print(TCNT1,DEC); | ||
Serial.print('\r'); // | Serial.print('\r'); // this will not work with embedded Serial Monitor, | ||
// | // but works fine with e.g. putty terminal | ||
delay(250); // wait 1/4s for another | |||
delay(250); // wait 1/4s for another measurement | |||
} | } | ||
Verzia z 09:38, 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; // initialize (CLEAR)counter
TCCR1B = 0x07; // T1 clk = 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'); // this will not work with embedded Serial Monitor,
// but works fine with e.g. putty terminal
delay(250); // wait 1/4s for another measurement
}