From 94a0d2ab8073f58fb856ea7f3c57014a7f3338ae Mon Sep 17 00:00:00 2001 From: Elena of Valhalla'' Grandi Date: Sun, 5 May 2013 16:13:02 +0200 Subject: Arduino sketch: take commands from a PS2 keyboard on pins 2,3 Uses the PS2Keyboard library from http://www.pjrc.com/teensy/td_libs_PS2Keyboard.html --- arduino_sketch/rfc4824/rfc4824.ino | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'arduino_sketch') 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 +#include #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); -- cgit v1.2.3