int ledPin = 13; //Led connecto to digital pin 13
int up = 11;
int down = 10;
int left = 9;
int right = 8;
char inChar; // Where to store the character read

void setup() {
  Serial.begin(9600);	// abre el puerto serie a 9600 bps
  Serial.flush(); // Limpia el buffer
  pinMode(up, OUTPUT); // initialize the digital pin as an output.
  pinMode(down, OUTPUT); // initialize the digital pin as an output.
  pinMode(left, OUTPUT); // initialize the digital pin as an output.
  pinMode(right, OUTPUT); // initialize the digital pin as an output.
}
void loop()
{
  while (Serial.available() == 0); //Espera a recibir datos
  inChar = (char)Serial.read(); // get the new byte:   
  digitalWrite(ledPin, HIGH);   // set the LED on  
  switch (inChar) {
    case 'D': //Abajo
      digitalWrite(up, LOW); 
      digitalWrite(down, HIGH);
      digitalWrite(left, LOW);
      digitalWrite(right, LOW);
      break;
    case 'Z': //Abajo-Izquierda
      digitalWrite(up, LOW); 
      digitalWrite(down, HIGH);
      digitalWrite(left, HIGH);
      digitalWrite(right, LOW);
      break;
    case 'X': //Abajo-Derecha
      digitalWrite(up, LOW); 
      digitalWrite(down, HIGH);
      digitalWrite(left, LOW);
      digitalWrite(right, HIGH);
      break;
    case 'L': //Izquierda
      digitalWrite(up, LOW); 
      digitalWrite(down, LOW);
      digitalWrite(left, HIGH);
      digitalWrite(right, LOW);
      break;
    case 'R': //Derecha
      digitalWrite(up, LOW); 
      digitalWrite(down, LOW);
      digitalWrite(left, LOW);
      digitalWrite(right, HIGH);
      break;
    case 'U': //Arriba
      digitalWrite(up, HIGH); 
      digitalWrite(down, LOW);
      digitalWrite(left, LOW);
      digitalWrite(right, LOW);
      break;
    case 'Q': //Arriba-Izquierda
      digitalWrite(up, HIGH); 
      digitalWrite(down, LOW);
      digitalWrite(left, HIGH);
      digitalWrite(right, LOW);
      break;
    case 'E': //Arriba-Derecha
      digitalWrite(up, HIGH); 
      digitalWrite(down, LOW);
      digitalWrite(left, LOW);
      digitalWrite(right, HIGH);
      break;
    default: 
      digitalWrite(up, LOW);   // set the LED off
      digitalWrite(down, LOW);   // set the LED off
      digitalWrite(left, LOW);   // set the LED off
      digitalWrite(right, LOW);   // set the LED off
      digitalWrite(ledPin, LOW);   // set the LED off
      // el "default" es opcional
  }
}
