Advertisement
Gabrielddsp

Arduino + Modulo Bluetooth + Motor de passo

Apr 27th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 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 = 200;
  19.  
  20. }
  21.  
  22. void loop() {
  23.  
  24.  
  25.  
  26.   if (Serial.available() > 0){   //Motor ligado para um lado.
  27.     entrada = Serial.read();
  28.     if(entrada == '1' || entrada == 'e'){
  29.     for(numeroLed = 0; numeroLed <= 5; numeroLed = numeroLed + 1){
  30.       digitalWrite(pinLed[numeroLed], HIGH);
  31.       delay(velocidade);
  32.       digitalWrite(pinLed[numeroLed],LOW);
  33.       delay(velocidade);
  34.    
  35.     if(numeroLed > 4) {
  36.       numeroLed = 0;
  37.     }
  38.     }  
  39.     }
  40.   }
  41.  
  42.   else if (entrada == '2' || entrada == 'd'){   //Motor ligado para o outro lado
  43.     for(numeroLed = 5; numeroLed >= 0; numeroLed = numeroLed - 1){
  44.       digitalWrite(pinLed[numeroLed], HIGH);
  45.       delay(velocidade);
  46.       digitalWrite(pinLed[numeroLed], LOW);
  47.       delay(velocidade);
  48.    
  49.     if(numeroLed > 4) {
  50.       numeroLed = 5;
  51.     }
  52.     }  
  53.   }  
  54.  
  55.   else if (entrada == '0' || entrada == 'a'){   //Motor desligado
  56.       digitalWrite(pinLed[numeroLed], LOW);
  57.       delay(velocidade);
  58.    
  59.     if(numeroLed < 1) {
  60.       numeroLed = 0;
  61.     }
  62.   }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement