diff options
-rw-r--r-- | arduino_sketch/rfc4824/rfc4824.ino | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/arduino_sketch/rfc4824/rfc4824.ino b/arduino_sketch/rfc4824/rfc4824.ino index 95d0c21..c4c0331 100644 --- a/arduino_sketch/rfc4824/rfc4824.ino +++ b/arduino_sketch/rfc4824/rfc4824.ino @@ -1,5 +1,6 @@ #include <Stepper.h> +#include <PS2Keyboard.h> #define ADJ_STP 32 #define ADJ_SPEED 128 @@ -10,7 +11,10 @@ Stepper left_arm(64,4,5,6,7); Stepper right_arm(64,8,9,10,11); -int c; +PS2Keyboard keyboard; + +#define KBD_DATA 2 +#define KBD_CLOCK 3 int pos[16][2] = { {1,0}, {2,0}, {3,0}, {4,0}, {0,3}, {0,2}, {0,1}, {2,-1}, @@ -19,12 +23,18 @@ int pos[16][2] = { {1,0}, {2,0}, {3,0}, {4,0}, void setup() { Serial.begin(9600); + keyboard.begin(KBD_DATA,KBD_CLOCK); left_arm.setSpeed(QRT_SPEED); right_arm.setSpeed(QRT_SPEED); } void loop() { - read_serial_commands(); + if (Serial.available()) { + read_commands(Serial.read()); + } + if (keyboard.available()) { + read_commands(keyboard.read()); + } } void adjust(char motor,int steps) { @@ -48,8 +58,7 @@ void adjust(char motor,int steps) { Serial.println(" steps"); } -void read_serial_commands() { - c = Serial.read(); +void read_commands(int c) { switch (c) { case 'o': adjust('l',ADJ_STP); |