summaryrefslogtreecommitdiffstats
path: root/avr.cpp
diff options
context:
space:
mode:
authorneoraider <devnull@localhost>2007-04-18 00:10:05 +0200
committerneoraider <devnull@localhost>2007-04-18 00:10:05 +0200
commite7e1634240c78c7abbdc7fc6e0af1beddaea1d45 (patch)
treee09406ef8e02fbd7923734acb2e36d5e93d8f6db /avr.cpp
parentd02fbc84105ff2da74f03fd658ace8919e3e9437 (diff)
downloadrc2007-rescue-e7e1634240c78c7abbdc7fc6e0af1beddaea1d45.tar
rc2007-rescue-e7e1634240c78c7abbdc7fc6e0af1beddaea1d45.zip
Linienverfolgung implementiert
Diffstat (limited to 'avr.cpp')
-rw-r--r--avr.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/avr.cpp b/avr.cpp
index fca50fb..cd528ba 100644
--- a/avr.cpp
+++ b/avr.cpp
@@ -1,5 +1,6 @@
#include "avr.h"
#include "adc.h"
+#include "global.h"
#include "util.h"
#include <stdint.h>
@@ -21,3 +22,22 @@ void waitForButton(int i) {
while(getButton() != CLAMP(0, i, 5));
while(getButton() != 0);
}
+
+void beep(unsigned long freq) {
+ const int prescalers[7] = {1, 8, 32, 64, 128, 256, 1024};
+
+ for(int i = 0; i < 7; i++) {
+ if(F_CPU/freq/2/prescalers[i] <= 256) {
+ TCCR2 = (TCCR2&~0x07)|(i+1);
+ OCR2 = F_CPU/freq/2/prescalers[i] - 1;
+
+ return;
+ }
+ }
+
+ beepOff();
+}
+
+void beepOff() {
+ TCCR2 &= ~0x07;
+}