forked from rookie/FrequencyTimer2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add example corrected from online example
- Loading branch information
Matt
authored and
Matt
committed
Jun 16, 2010
1 parent
4a12010
commit d8ff780
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include <FrequencyTimer2.h> | ||
|
||
void setup() { | ||
pinMode(11,OUTPUT); | ||
|
||
Serial.begin(19200); | ||
delay(2); | ||
Serial.print("Ready"); | ||
|
||
FrequencyTimer2::setPeriod(200); | ||
FrequencyTimer2::enable(); | ||
} | ||
|
||
long burpCount = 0; | ||
void Burp(void) { | ||
burpCount++; | ||
} | ||
|
||
void loop() { | ||
static unsigned long v = 0; | ||
if ( Serial.available()) { | ||
char ch = Serial.read(); | ||
switch(ch) { | ||
case '0'...'9': | ||
v = v * 10 + ch - '0'; | ||
break; | ||
case 'p': | ||
FrequencyTimer2::setPeriod(v); | ||
Serial.print("set "); | ||
Serial.print((long)v, DEC); | ||
Serial.print(" = "); | ||
Serial.print((long)FrequencyTimer2::getPeriod(), DEC); | ||
Serial.println(); | ||
v = 0; | ||
break; | ||
case 'e': | ||
FrequencyTimer2::enable(); | ||
break; | ||
case 'd': | ||
FrequencyTimer2::disable(); | ||
break; | ||
case 'o': | ||
FrequencyTimer2::setOnOverflow( Burp); | ||
break; | ||
case 'n': | ||
FrequencyTimer2::setOnOverflow(0); | ||
break; | ||
case 'b': | ||
Serial.println(burpCount,DEC); | ||
break; | ||
case 'x': | ||
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) | ||
Serial.print("TCCR2A:"); | ||
Serial.println(TCCR2A,HEX); | ||
Serial.print("TCCR2B:"); | ||
Serial.println(TCCR2B,HEX); | ||
Serial.print("OCR2A:"); | ||
Serial.println(OCR2A,HEX); | ||
#else | ||
Serial.print("TCCR2:"); | ||
Serial.println(TCCR2,HEX); | ||
Serial.print("OCR2:"); | ||
Serial.println(OCR2,HEX); | ||
#endif | ||
Serial.print("TCNT2:"); | ||
Serial.println(TCNT2,HEX); | ||
|
||
break; | ||
} | ||
} | ||
} |