Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • Thank you for getting involved - it is much appreciated. I have tried to follow your suggestions and I have altered my code accordingly, however, I get an error message saying "debounced" not declared in this scope. I'm not sure if I am reading this correctly but I see that the if (debounced) statement comes before the Bool debounce statement - does this have an impact on the program? Commented Oct 4, 2024 at 12:50
  • My code now looks like this: void revmotor (){ if (debounced()) setdir = !setdir; } bool debounce() { static uint16_t state = 0; state = (state<<1) | digitalRead(reverseSwitch) | 0xfe00; return (state == 0xff00); } void setup() { pinMode (driverPUL, OUTPUT); pinMode (driverDIR, OUTPUT); attachInterrupt(digitalPinToInterrupt(reverseSwitch), revmotor, FALLING); } Commented Oct 4, 2024 at 12:53
  • OK - problem solved - tiny spelling error debounce / debounced. code is running now although the debounce action is still a little erratic. I'll keep experimenting. Thank you. Commented Oct 4, 2024 at 12:58
  • You could change the 0xfe00 to 0x8000 and 0xff00 to 0xc000 to have longer debouncing period. Commented Oct 5, 2024 at 4:26
  • Thank you again for your input. For me to understand what this change will do, could you explain what the changes mean please. Commented Oct 6, 2024 at 12:30