Advertisement
Gabrielddsp

Arduino + Modulo Bluetooth + Motor de passo

Apr 27th, 2017
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. int pinLed[6] = {3,4,5,6,7,8};
  2. int velocidade;
  3. int numeroLed;
  4. int x;
  5. int entrada;
  6.  
  7. void setup() {
  8.  
  9.  
  10.  
  11.  
  12.   for(x = 0; x <= 5; x = x + 1){
  13.     pinMode(pinLed[x], OUTPUT);
  14.   }
  15.  
  16.   Serial.begin(9600);
  17.  
  18.   velocidade = 5;
  19.  
  20. }
  21.  
  22. void loop() {
  23.  
  24.  
  25.  
  26.   if (Serial.available() > 0){  
  27.     entrada = Serial.read();}
  28.  
  29.  
  30.  
  31.  
  32.   else if (entrada == '2' || entrada == 'd'){   //Motor ligado para o outro lado
  33.     for(numeroLed = 0; numeroLed <= 5; numeroLed = numeroLed + 1){
  34.       digitalWrite(pinLed[numeroLed], HIGH);
  35.       delay(velocidade);
  36.       digitalWrite(pinLed[numeroLed], LOW);
  37.       delay(velocidade);
  38.    
  39.     if(numeroLed > 4) {
  40.       numeroLed = 5;
  41.     }
  42.     }  
  43.   }  
  44.  
  45.   else if (entrada == '0' || entrada == 'a'){   //Motor desligado
  46.       digitalWrite(pinLed[numeroLed], LOW);
  47.       delay(velocidade);
  48.   }
  49.  
  50.     else if (entrada == '3' || entrada == 'e'){   //Motor ligado para o outro lado
  51.     for(numeroLed = 5; numeroLed >= 0; numeroLed = numeroLed - 1){
  52.       digitalWrite(pinLed[numeroLed], HIGH);
  53.       delay(velocidade);
  54.       digitalWrite(pinLed[numeroLed], LOW);
  55.       delay(velocidade);
  56.    
  57.     if(numeroLed > 4) {
  58.       numeroLed = 5;
  59.     }
  60.     }  
  61.   }
  62.      
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement