Advertisement
Guest User

Motor de passo + LDR

a guest
Dec 17th, 2014
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1.  
  2. #include <AFMotor.h>
  3. int sensor = 0;      
  4. int valorSensor = 0;
  5.  
  6. int x=0;
  7. int y=0;
  8.  
  9. volatile int state1 = LOW;
  10. volatile long lastDebounceTime = 0;
  11. long debounceDelay = 10;
  12.  
  13. const int ledVermelho = 13;
  14.  
  15. AF_Stepper motor(200, 1);
  16.  
  17. void setup(){
  18.  
  19.   Serial.begin(9600);
  20.   pinMode(ledVermelho,OUTPUT);    
  21.   motor.setSpeed(10);  
  22.   attachInterrupt(0, debounce, FALLING);
  23.  
  24. }
  25.  
  26. void loop(){
  27.  
  28.   int valorSensor = analogRead(sensor);
  29.   Serial.println(valorSensor);
  30.  
  31.   if (valorSensor < 30) {
  32.     apagaLeds();
  33.     digitalWrite(ledVermelho,HIGH);
  34.   }
  35.  
  36.   if (valorSensor > 30) {
  37.     apagaLeds();
  38.  
  39.  
  40.  
  41.   }
  42.  
  43.  if (y==0){
  44.    
  45.   while(x<7){
  46.     motor.step(1, FORWARD, SINGLE);
  47.    x++;
  48.   //Serial.println(x);
  49.  
  50.   }
  51.  
  52.   while(x>0){
  53.      motor.step(1, BACKWARD, SINGLE);
  54.     x--;
  55.     //Serial.println(x);
  56.    
  57.   }
  58.  }
  59.  
  60. if (y==1){
  61. }
  62. }
  63.  
  64. void apagaLeds() {
  65.  
  66.   digitalWrite(ledVermelho,LOW);
  67. }
  68.   void debounce(){
  69.    
  70.      
  71.   long currentTime = millis();
  72.  
  73.   if ((currentTime - lastDebounceTime) > debounceDelay)
  74.   {
  75.     lastDebounceTime = currentTime;
  76.    
  77.    desliga();
  78.    
  79.   }
  80.   }
  81.  
  82.   void desliga() {
  83.     //Serial.println(y);
  84.     y = !y;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement