diff options
author | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2012-11-18 10:22:45 +0100 |
---|---|---|
committer | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2012-11-18 10:22:45 +0100 |
commit | 4ec2e3d023728c14badbd766fd60f4088315b09b (patch) | |
tree | 8907d06c48420b34a612ee6d54e2526f2030c67f /arduino_sketch | |
parent | 92aff561a6e32f009a914f86fe2385371c6b9216 (diff) |
arduino sketch: hex codes
Diffstat (limited to 'arduino_sketch')
-rw-r--r-- | arduino_sketch/rfc4824/rfc4824.ino | 188 |
1 files changed, 186 insertions, 2 deletions
diff --git a/arduino_sketch/rfc4824/rfc4824.ino b/arduino_sketch/rfc4824/rfc4824.ino index f2ce79c..a0a2fd3 100644 --- a/arduino_sketch/rfc4824/rfc4824.ino +++ b/arduino_sketch/rfc4824/rfc4824.ino @@ -1,8 +1,14 @@ #include <Stepper.h> -Stepper left_arm(64,2,3,4,5); -Stepper right_arm(64,7,8,9,10); +#define ADJ_STP 256 +#define QRT_STP 256 +#define CHAR_DELAY 1000 + +Stepper left_arm(64,4,5,6,7); +Stepper right_arm(64,8,9,10,11); + +int c; void setup() { Serial.begin(9600); @@ -11,4 +17,182 @@ void setup() { } void loop() { + read_serial_commands(); +} + +void adjust(char motor,int steps) { + Serial.print("Adjusting "); + switch (motor) { + case 'l': + Serial.print("left"); + left_arm.step(steps); + break; + case 'r': + Serial.print("right"); + right_arm.step(steps); + break; + } + Serial.print(" motor of "); + Serial.print(steps,DEC); + Serial.println(" steps"); +} + +void read_serial_commands() { + c = Serial.read(); + switch (c) { + case 'o': + adjust('l',ADJ_STP); + break; + case 'p': + adjust('l',-ADJ_STP); + break; + case 'n': + adjust('r',ADJ_STP); + break; + case 'm': + adjust('r',-ADJ_STP); + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + set_hex(c-'0'); + break; + case 'a': + case 'A': + set_hex(0xA); + break; + case 'b': + case 'B': + set_hex(0xB); + break; + case 'c': + case 'C': + set_hex(0xC); + break; + case 'd': + case 'D': + set_hex(0xD); + break; + case 'e': + case 'E': + set_hex(0xE); + break; + case 'f': + case 'F': + set_hex(0xF); + break; + } +} + +void set_hex(char digit) { + Serial.print("Going to position "); + Serial.println(digit,HEX); + switch (digit) { + case 0x0: + right_arm.step(QRT_STP); + delay(CHAR_DELAY); + right_arm.step(-QRT_STP); + break; + case 0x1: + right_arm.step(QRT_STP*2); + delay(CHAR_DELAY); + right_arm.step(-QRT_STP*2); + break; + case 0x2: + right_arm.step(QRT_STP*3); + delay(CHAR_DELAY); + right_arm.step(-QRT_STP*3); + break; + case 0x3: + right_arm.step(QRT_STP*4); + delay(CHAR_DELAY); + right_arm.step(-QRT_STP*4); + break; + case 0x4: + left_arm.step(-QRT_STP*3); + delay(CHAR_DELAY); + left_arm.step(QRT_STP*3); + break; + case 0x5: + left_arm.step(-QRT_STP*2); + delay(CHAR_DELAY); + left_arm.step(QRT_STP*2); + break; + case 0x6: + left_arm.step(-QRT_STP); + delay(CHAR_DELAY); + left_arm.step(QRT_STP); + break; + case 0x7: + right_arm.step(QRT_STP*2); + left_arm.step(QRT_STP); + delay(CHAR_DELAY); + right_arm.step(-QRT_STP*2); + left_arm.step(-QRT_STP); + break; + case 0x8: + right_arm.step(QRT_STP*3); + left_arm.step(QRT_STP); + delay(CHAR_DELAY); + right_arm.step(-QRT_STP*3); + left_arm.step(-QRT_STP); + break; + case 0x9: + right_arm.step(QRT_STP*4); + left_arm.step(-QRT_STP*2); + delay(CHAR_DELAY); + right_arm.step(-QRT_STP*4); + left_arm.step(QRT_STP*2); + break; + case 0xA: + right_arm.step(QRT_STP); + left_arm.step(-QRT_STP*4); + delay(CHAR_DELAY); + right_arm.step(-QRT_STP); + left_arm.step(QRT_STP*4); + break; + case 0xB: + right_arm.step(QRT_STP); + left_arm.step(-QRT_STP*3); + delay(CHAR_DELAY); + right_arm.step(-QRT_STP); + left_arm.step(QRT_STP*3); + break; + case 0xC: + right_arm.step(QRT_STP); + left_arm.step(-QRT_STP*2); + delay(CHAR_DELAY); + right_arm.step(-QRT_STP); + left_arm.step(QRT_STP*2); + break; + case 0xD: + right_arm.step(QRT_STP); + left_arm.step(-QRT_STP); + delay(CHAR_DELAY); + right_arm.step(-QRT_STP); + left_arm.step(QRT_STP); + break; + case 0xE: + right_arm.step(QRT_STP*2); + left_arm.step(-QRT_STP*5); + delay(CHAR_DELAY); + right_arm.step(-QRT_STP*2); + left_arm.step(QRT_STP*5); + break; + case 0xF: + right_arm.step(QRT_STP*2); + left_arm.step(-QRT_STP*4); + delay(CHAR_DELAY); + right_arm.step(-QRT_STP*2); + left_arm.step(QRT_STP*4); + break; + } + Serial.println("Returned to home position"); } |