Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define ENCODER_PIN 2
- volatile unsigned long clicks = 0;
- unsigned long last_clicks = 0;
- void setup() {
- Serial.begin(9600);
- // tried INPUT, INPUT_PULLUP and even commenting out the pinMode
- pinMode(ENCODER_PIN, INPUT);
- // tried CHANGE, RISING and FALLING
- attachInterrupt(digitalPinToInterrupt(ENCODER_PIN), encoder_isr, CHANGE);
- Serial.println("Interrupt attached");
- }
- void loop() {
- if (clicks != last_clicks) {
- Serial.print("Clicks: ");
- Serial.println(clicks);
- last_clicks = clicks;
- }
- delay(1000);
- }
- void encoder_isr() {
- clicks++;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement