Not sure how to work with char bits...

  1. 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
  2. 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".
  3. I'm not sure what a char should be referred to as, conversationally.
  4. 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.
    }
  }
}
  1. 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'

The variable 'c' is of the type 'char'.
http://arduino.cc/en/Reference/Char

The variable is declared with 'char', and used as 'c'.

// declare variables
char c;
char d,e;
int n;
long t;

// assign a value to the variables
c = 'A';
d = Serial.read();
e = keyboard.read();
n = 132;
t = 343242;

What you are trying to do is declaring a fresh new variable 'c' inside the 'if' statement.
You also compare a single character with a string. Using double quotes is for a string, using single quotes is for a single character.

It should be something like this:

if ( c == 'A' )
{
  ...
}
else if ( c == 'B')
{
  ...
}

Thanks! BTW I tried simply using something like

if (c == "a")

earlier, but I came up with a "could not compare pointer with integer" error; apparently single-quotes help.

EDIT: Can't seem to get multiple conditions to work, i.e.

if (c == 'a') {
      digitalWrite(13, HIGH);
      delay(1000);
      digitalWrite(13, LOW);
    }
    
    if (c == 's') {
      digitalWrite(10, HIGH);
      delay(1000);
      digitalWrite(10, LOW);

Sure, the "light up pin 13 for a second if A is pressed" bit works, but I can't get pin 10 to light up at all, even when I change 13 to 10 and get rid of the part starting with "if (c == s) {" .

EDIT 2: Weird, I can't get any pin besides pin 13 to light up. Maybe I should try taking off the SD card shield.
EDIT 3: So apparently I didn't declare pin 10. D'oh.