Advertisement
tomateblue

MotorDePassos

Oct 18th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.98 KB | None | 0 0
  1. #define b0 2
  2. #define b1 3
  3. #define b2 4
  4. #define b3 5
  5. /**************
  6.  * Tarefa: Implementar uma funรงรฃo que
  7.  * receba a velocidade do motor e calcule
  8.  * o valor apropriado do delay;
  9.  *
  10.  * Implementar o giro nos 2 sentidos de rotaรงรฃo
  11. **/
  12. byte i;
  13. unsigned long t;
  14.  
  15. void enviaBits(byte B);
  16.  
  17. void setup() {
  18.   pinMode(b0,OUTPUT);
  19.   pinMode(b1,OUTPUT);
  20.   pinMode(b2,OUTPUT);
  21.   pinMode(b3,OUTPUT);
  22.   i = 1;
  23.   t = millis(); // tempo inicial
  24. }
  25.  
  26. void loop() {
  27.    if ( (millis()-t) >20 ){
  28.    enviaBits(i);
  29.    i *= 2;
  30.    if(i > 8) i = 1;
  31.    t = millis(); // atualiza o valor da contagem    
  32.    }
  33.    //delay(10); // RUIM
  34. }
  35.  
  36. //****************//
  37.  
  38. void enviaBits(byte B){
  39.  
  40.     bool bit;
  41.     byte aux = B;
  42.  
  43.     bit = aux % 2;
  44.     digitalWrite(b0,bit);
  45.  
  46.     aux = aux>>1;
  47.     bit = aux % 2;
  48.     digitalWrite(b1,bit);
  49.  
  50.     aux = aux>>1;
  51.     bit = aux % 2;
  52.     digitalWrite(b2,bit);
  53.    
  54.     aux = aux>>1;
  55.     bit = aux % 2;
  56.     digitalWrite(b3,bit);
  57.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement