domingo, 2 de dezembro de 2012

codigo para 16 comandos

void setup()
 {
  Serial.begin(9600);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(11,OUTPUT);
  pinMode(12,OUTPUT);
  pinMode(22,OUTPUT);
  pinMode(23,OUTPUT);
  pinMode(24,OUTPUT);
  pinMode(25,OUTPUT);
  pinMode(26,OUTPUT);
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);
  digitalWrite(10,LOW);
  digitalWrite(11,LOW);
  digitalWrite(12,LOW);
  digitalWrite(22,LOW);
  digitalWrite(23,LOW);
  digitalWrite(24,LOW);
  digitalWrite(25,LOW);
  digitalWrite(26,LOW);
  }

 void loop()
{
 if (Serial.available())
     {
      int c = Serial.read();
      if (c == 'w')
        {
          digitalWrite(2, HIGH);
          digitalWrite(4, HIGH);
          Serial.println("Frente");
          delay(100);           
          digitalWrite(2, LOW);
          digitalWrite(4, LOW);
         }
      }
      {
        int c = Serial.read();
        if (c == 's')
          {
          digitalWrite(3, HIGH);
          digitalWrite(5, HIGH);
          Serial.println("Trás");
          delay(100);           
          digitalWrite(3, LOW);
          digitalWrite(5, LOW);
                          
          }
        }
      {
        int c = Serial.read();
        if (c == 'a')
        {
          digitalWrite(2, HIGH);
          digitalWrite(5, HIGH);
          Serial.println("Direita");
          delay(100);           
          digitalWrite(2, LOW);
          digitalWrite(5, LOW);
                          
        }
      }
        {
        int c = Serial.read();
        if (c == 'd')
             {
               digitalWrite(3, HIGH);
               digitalWrite(4, HIGH);
               Serial.println("Esquerda");
               delay(100);           
               digitalWrite(3, LOW);
               digitalWrite(4, LOW);
                          
             }
        }
        {
        int c = Serial.read();
        if (c == 'Q')
             {
               digitalWrite(6, HIGH);
               Serial.println("gir.e");
               delay(100);           
               digitalWrite(6, LOW);
             }
        }
        {
        int c = Serial.read();
        if (c == 'e')
             {
               digitalWrite(7, HIGH);
               Serial.println("gir.d");
               delay(100);           
               digitalWrite(7, LOW);
              }
        }
        {
        int c = Serial.read();
        if (c == 'r')
             {
               digitalWrite(8,HIGH);
               Serial.println("bras.s");
               delay(100);           
               digitalWrite(8,LOW);
              }
        }
        {
        int c = Serial.read();
        if (c == 'f')
             {
               digitalWrite(9,HIGH);
               Serial.println("bras.d");
               delay(100);           
               digitalWrite(9,LOW);
               }
        }
        {
        int c = Serial.read();
        if (c == 't')
             {
               digitalWrite(10,HIGH);
               Serial.println("a.bras.s");
               delay(100);           
               digitalWrite(10,LOW);
             }
        }
        {
        int c = Serial.read();
        if (c == 'g')
             {
               digitalWrite(11,HIGH);
               Serial.println("a.bras.d");
               delay(100);           
               digitalWrite(11,LOW);
             }
        }
        {
        int c = Serial.read();
        if (c == 'y')
             {
               digitalWrite(12,HIGH);
               Serial.println("pul.s");
               delay(100);           
               digitalWrite(12,LOW);
             }
        }
        {
        int c = Serial.read();
        if (c == 'h')
             {
               digitalWrite(22,HIGH);
               Serial.println("pul.d");
               delay(100);           
               digitalWrite(22,LOW);
             }
        }
        {
        int c = Serial.read();
        if (c == 'i')
             {
               digitalWrite(23,HIGH);
               Serial.println("gpul.h");
               delay(100);
               digitalWrite(23,LOW);
             }
        }
        {
        int c = Serial.read();
        if (c == 'u')
             {
               digitalWrite(24,HIGH);
               Serial.println("gpul.a");
               delay(100);
               digitalWrite(24,LOW);
             }
        }
        {
        int c = Serial.read();
        if (c == 'j')
             {
               digitalWrite(25,HIGH);
               Serial.println("pin.a");
               delay(100);
               digitalWrite(25,LOW);
             }
        }
        {
        int c = Serial.read();
        if (c == 'k')
             {
               digitalWrite(26,HIGH);
               Serial.println("pin.f");
               delay(100);
               digitalWrite(26,LOW);
             }
        }
}

Um comentário: