Quick question: probably a simple error

I am making an interface for the arduino to processing involving a joystick. It should work so the processing sketch sends the character 'b' or 'c' depending on if it wants to find the state of the 'b'utton on the joystick or the 'c'oordinates of the position of the joystick. ( a number 1-9, set up like a telephone keypad.)

I have been testing the arduino side in the serial monitor, but with no luck. Nothing gets sent back.
I think this may just be a simple error I did not catch, but here's the code:

byte req;

byte crossGet()  {
  byte coor = 5;
  if(digitalRead(3) == HIGH)  {
    coor += 3;
  }
  if(digitalRead(5) == HIGH)  {
    coor -= 3;
  }
  if(digitalRead(4) == HIGH)  {
    coor --;
  }
  if(digitalRead(6) == HIGH)  {
    coor ++;
  }
  return coor;
}

byte pressed()  {
  byte res;
  if(digitalRead(7)==LOW)  {
    res=1;
  }
  else  {
    res=0;
  }
  return res;
}

void setup()  {
  for(int i=3; i<=7; i++) {
    pinMode(i, INPUT);
    digitalWrite(i, HIGH);
  }
  pinMode(2, OUTPUT);
  digitalWrite(2, LOW);
  Serial.begin(57600);
}


void loop()  {
  req = 'n';
  if(Serial.available()>0)  {
    req = Serial.read();
    if(req == 'c')  {
      byte coor = crossGet();
      Serial.print(coor);
    }
    else if(req == 'b')  {
      byte press = pressed();
      Serial.print(press);
    }
  }

}

By the way the arduino can read the joystick itself properly. It is one of the ones used in claw machines: 4 switches and one more for the red button on top. The switches are wired to pins 3-7, and pin 2 acts as a connection to ground so the joystick can be connected by one row of headers on the end of a ribbon cable.

Does this help...

void loop()  {
  req = 'n';
  if(Serial.available()>0)  {
    req = Serial.read();
    if(req == 'c')  {
      byte coor = crossGet();
      Serial.print(coor[glow], DEC[/glow]);
    }
    else if(req == 'b')  {
      byte press = pressed();
      Serial.print(press[glow], DEC[/glow]);
    }
  }

}

If, by "nothing gets sent back", you mean that Processing does not get any data, then, we'd need to see the processing code, too.

Typically, though, you need to include a carriage return at the end of the data being sent. Either use Serial.println to send the data, or add Serial.print("\n"); after the (last) Serial.print.

I'm not currently using the processing side. As I said, I was testing it in the serial monitor.

How are you testing this?

Do you realise that the serial monitor doesn't transmit single key-presses as they are made, but only when you hit "return"?

Yes I've been typing b or c then pressing enter.
I've also tried sending the decimal ASCII equivalent, I didn't really think it would work, and it doesn't.

Oh, and the rx light flashes, so it is recieving the byte. No transmitting though.

Try echoing the data being received, using Serial.print. Try printing something in setup, using Serial.print.

I just got a chance to try some stuff with the code, and I got it to work.
Thanks, Coding Badly, the DEC addition fixed it.
My question is, why exactly does this solution work?

pressed returns one of these single byte values: 0x01 or 0x00. crossGet returns one of these single byte values: 0x05, 0x08, 0x02, 0x04, 0x06. Serial.print(coor) and Serial.print(press) send that single byte, unmodified, to the PC. Byte values less than 0x20 are "non printable characters". So, your Sketch was sending data to the PC but Serial Monitor wasn't displaying it.

Serial.print(coor,DEC) and Serial.print(press,DEC) first convert the byte value to a text string and then send the string over the serial port to the PC. 0x00 is converted to "0"; 0x01 is converted to "1", etcetera. Serial Montior then displays the converted strings.

Does that make sense?

Oh, okay.
That makes sense.
Thanks!