- I am attempting to work with the output of the PS2 Keyboard library, so that I can turn LEDs on and off, or run motors.
Arduino Playground - HomePage - Despite being able to run the sample program perfectly (and changing the keyboard type accordingly for my keyboard), I cannot make use of the char "c" or "keyboard.read".
- I'm not sure what a char should be referred to as, conversationally.
- Here's my code, a modified version of the sample code:
/* PS2Keyboard library, International Keyboard Layout Example
http://www.pjrc.com/teensy/td_libs_PS2Keyboard.html
keyboard.begin() accepts an optional 3rd parameter to
configure the PS2 keyboard layout. Uncomment the line for
your keyboard. If it doesn't exist, you can create it in
PS2Keyboard.cpp and email paul@pjrc.com to have it included
in future versions of this library.
*/
#include <PS2Keyboard.h>
const int DataPin = 8;
const int IRQpin = 3;
PS2Keyboard keyboard;
void setup() {
keyboard.begin(DataPin, IRQpin, PS2Keymap_US);
//keyboard.begin(DataPin, IRQpin, PS2Keymap_German);
//keyboard.begin(DataPin, IRQpin, PS2Keymap_French);
Serial.begin(9600);
Serial.println("'MURICAN Keyboard Test:"); //This works fine.
pinMode(13, OUTPUT);
}
void loop() { //This is unchanged from the sample program.
if (keyboard.available()) { //This is unchanged from the sample program.
char c = keyboard.read(); //This is unchanged from the sample program.
Serial.print(c); //This is unchanged from the sample program.
if (char c == "a") { //This I added on, and this is the source of the error.
digitalWrite(13, HIGH); //Light up the onboard LED.
delay(500); //Wait half a second.
digitalWrite(13, LOW); //Turn it back off.
}
}
}
- The error by itself, caused by the line, the first line I added:
if (char c == "a") {
MURICAN_Keyboard_Test_Blinky:32: error: expected primary-expression before 'char'
MURICAN_Keyboard_Test_Blinky:32: error: expected `)' before 'char'