Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <AFMotor.h>
- int sensor = 0;
- int valorSensor = 0;
- int x=0;
- int y=0;
- volatile int state1 = LOW;
- volatile long lastDebounceTime = 0;
- long debounceDelay = 10;
- const int ledVermelho = 13;
- AF_Stepper motor(200, 1);
- void setup(){
- Serial.begin(9600);
- pinMode(ledVermelho,OUTPUT);
- motor.setSpeed(10);
- attachInterrupt(0, debounce, FALLING);
- }
- void loop(){
- int valorSensor = analogRead(sensor);
- Serial.println(valorSensor);
- if (valorSensor < 30) {
- apagaLeds();
- digitalWrite(ledVermelho,HIGH);
- }
- if (valorSensor > 30) {
- apagaLeds();
- }
- if (y==0){
- while(x<7){
- motor.step(1, FORWARD, SINGLE);
- x++;
- //Serial.println(x);
- }
- while(x>0){
- motor.step(1, BACKWARD, SINGLE);
- x--;
- //Serial.println(x);
- }
- }
- if (y==1){
- }
- }
- void apagaLeds() {
- digitalWrite(ledVermelho,LOW);
- }
- void debounce(){
- long currentTime = millis();
- if ((currentTime - lastDebounceTime) > debounceDelay)
- {
- lastDebounceTime = currentTime;
- desliga();
- }
- }
- void desliga() {
- //Serial.println(y);
- y = !y;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement