int A = 5;
int B = 4;
int SW = 19;
int anterior = 50;
volatile int posicion = 50;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(A, INPUT);
pinMode(B, INPUT);
pinMode(SW, INPUT);
attachInterrupt(digitalPinToInterrupt(A), encoder, HIGH);
Serial.println("Iniciado!");
}
void loop() {
// put your main code here, to run repeatedly:
if (posicion != anterior)
{
Serial.println(posicion);
anterior = posicion;
}
delay(10); // this speeds up the simulation
}
void encoder()
{
if (digitalRead(B) == HIGH)
posicion ++;
else
posicion --;
}