summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElena of Valhalla'' Grandi <valhalla.trueelena.org>2013-05-05 16:13:02 +0200
committerElena of Valhalla'' Grandi <valhalla.trueelena.org>2013-05-05 16:13:02 +0200
commit94a0d2ab8073f58fb856ea7f3c57014a7f3338ae (patch)
tree21cddb752ea0a7a88d4ade5cbb583e5b05bb02f2
parent504010e41efe1914e1486096564ffbd8dbf30fc3 (diff)
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
-rw-r--r--arduino_sketch/rfc4824/rfc4824.ino17
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);