Hot answers tagged

2

I think you may be confused as to what a "critical section" is. I see in your code where you are reading your button, but I don't see where you use it at all. To read your encoder with a critical section all you need is replace this: if( counter != temp ){ Serial.print("counter = "); Serial.print (counter); Serial.print(" ...


1

What happens if the while condition fails? i.e. if millis() - time is greater than or equal to 20. Is this what you intended? If there's too much other stuff in the while loop, it may quit it and never re-enter it. loop() I've added a call to a function that prints debug information. unsigned long time = 0; void loop() { DebugMsgTime("loop() begin&...


1

The way I see it, the state should go back to IdleState if the button is not pressed. Just putting the switch-case inside the if-statement will result in the motor continue rotating the way it was rotating when the button is released. if (button1State == LOW ) { State = IdleState; counter=2000; } else if(button1State==HIGH && State==IdleState ) { ...


Only top voted, non community-wiki answers of a minimum length are eligible