volatile int pin21 = 0;
volatile int pin20 = 0;
int antPin20 = 0;
int antPin21 = 0;
long Time = 0;
const int banda = 20;
void setup() {
Serial.begin(9600);
Serial.println("Wake up!\n");
pinMode(19, INPUT_PULLUP);
pinMode(20, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(21), remove, FALLING);
attachInterrupt(digitalPinToInterrupt(20), vueltaMas, FALLING);
}
void loop() {
if(antPin21 != pin21) {
Serial.print(pin21);
antPin21 = pin21;
}
if(antPin20 != pin20){
Serial.println(pin20);
antPin20 = pin20;
}
}
void vueltaMas() {
if (millis() - Time > banda){
pin21++;
Time = millis();
}
}
void remove(){
if (millis() - Time > banda){
pin20--;
Time = millis();
}
}