Skip to content

Commit

Permalink
add example corrected from online example
Browse files Browse the repository at this point in the history
  • 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.
71 changes: 71 additions & 0 deletions examples/FreqGenerater/FreqGenerater.pde
@@ -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;
}
}
}

0 comments on commit d8ff780

Please sign in to comment.