summaryrefslogtreecommitdiffstats
path: root/avr.cpp
diff options
context:
space:
mode:
authorneoraider <devnull@localhost>2007-04-04 14:08:03 +0200
committerneoraider <devnull@localhost>2007-04-04 14:08:03 +0200
commite26a1dc73313098cef235918d237f9b1a6e4cb5f (patch)
tree0dfc7f873db2f228b39509daed9b1e01cb5739dd /avr.cpp
parentdc1306244e3a7853c31cd94c5ac3d97aa6e6c0d5 (diff)
downloadrc2007-rescue-e26a1dc73313098cef235918d237f9b1a6e4cb5f.tar
rc2007-rescue-e26a1dc73313098cef235918d237f9b1a6e4cb5f.zip
Rescue: Weitere Grundfunktionen implementiert
Diffstat (limited to 'avr.cpp')
-rw-r--r--avr.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/avr.cpp b/avr.cpp
new file mode 100644
index 0000000..a5194a4
--- /dev/null
+++ b/avr.cpp
@@ -0,0 +1,34 @@
+#include "avr.h"
+#include "adc.h"
+#include "util.h"
+
+void setMotorSpeed(MOTOR *motor, int speed) {
+ if(speed > 0) {
+ *motor->port &= ~motor->revMask;
+ *motor->port |= motor->fwdMask;
+ }
+ else if(speed < 0) {
+ *motor->port &= ~motor->fwdMask;
+ *motor->port |= motor->revMask;
+ }
+ else *motor->port |= motor->fwdMask|motor->revMask;
+
+ *motor->pwmPort = CLAMP(0, ABS(speed), 255);
+}
+
+int getButton() {
+ uint16_t val = getADCValue(7);
+
+ if(val < 144) return 5;
+ if(val < 228) return 4;
+ if(val < 304) return 3;
+ if(val < 376) return 2;
+ if(val < 600) return 1;
+
+ return 0;
+}
+
+void waitForButton(int i) {
+ while(getButton() != CLAMP(0, i, 5));
+ while(getButton() != 0);
+}