This is my code:
Code: Select all
const byte ledPinIRSensor = 13;
const byte interruptPin = 3;
volatile byte state = LOW;
int rev = 0;
void setup() {
pinMode(ledPinIRSensor, OUTPUT);
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), triggerEncoder, RISING);
Serial.begin(115200);
}
void loop() {
digitalWrite(ledPinIRSensor, HIGH);
Serial.print("Number of revolutions: ");
Serial.println(rev);
}
void triggerEncoder() {
rev++;
}