SHARE
TWEET

arduino

richigarza Nov 8th, 2012 158 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int i = 0;
  2. #define ledIzq 4
  3. #define ledDer 5
  4. #define ledArr 6
  5. #define ledAba 7
  6. #define motor 13
  7.  
  8. // the setup routine runs once when you press reset:
  9. void setup() {    
  10.   Serial.begin(9600);
  11.   for (i=4; i<=7; i++){
  12.        pinMode(i, OUTPUT);        
  13.   }
  14.  
  15. }
  16.  
  17. // the loop routine runs over and over again forever:
  18. void loop() {
  19.   if(Serial.available()) {
  20.     char in = Serial.read();
  21.  
  22.     if(in == 'U'){
  23.         digitalWrite(ledArr, HIGH);
  24.         digitalWrite(ledAba, LOW);
  25.         digitalWrite(ledDer, LOW);
  26.         digitalWrite(ledIzq, LOW);
  27.         digitalWrite(motor, HIGH);
  28.         delay(2000);
  29.         digitalWrite(ledArr, LOW);
  30.         digitalWrite(motor, LOW);
  31.     }
  32.      
  33.     if(in == 'D'){
  34.         digitalWrite(ledArr, LOW);
  35.         digitalWrite(ledAba, HIGH);
  36.         digitalWrite(ledDer, LOW);
  37.         digitalWrite(ledIzq, LOW);
  38.         digitalWrite(motor, HIGH);
  39.         delay(1000);
  40.         digitalWrite(ledAba, LOW);
  41.         digitalWrite(motor, LOW);
  42.     }
  43.        
  44.     if(in == 'R'){
  45.         digitalWrite(ledArr, LOW);
  46.         digitalWrite(ledAba, LOW);
  47.         digitalWrite(ledDer, HIGH);
  48.         digitalWrite(ledIzq, LOW);
  49.         digitalWrite(motor, HIGH);
  50.         delay(1000);
  51.         digitalWrite(ledDer, LOW);
  52.         digitalWrite(motor, LOW);
  53.     }
  54.      
  55.     if(in == 'L'){
  56.         digitalWrite(ledArr, LOW);
  57.         digitalWrite(ledAba, LOW);
  58.         digitalWrite(ledDer, LOW);
  59.         digitalWrite(ledIzq, HIGH);
  60.         digitalWrite(motor, HIGH);
  61.         delay(1000);
  62.         digitalWrite(ledIzq, LOW);
  63.         digitalWrite(motor, LOW);
  64.     }
  65.    
  66.   }
  67. }
RAW Paste Data
Top