New answers tagged

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 ) { ...


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(" ...


-2

Arduino pins are defined only by a simple number, with the exception that the analog pins are also named as 'A0' through 'A8' (or however many analog pins the specific processor has). Thus, D2 is not defined. If you mean to refer to Arduino pin 2, its name is just '2'. So: #define ONE_WIRE_BUS D2 -> #define ONE_WIRE_BUS 2


-1

To verify communication via COM port (to send messages as well as to receive) you can use arduino emulator from wokwi.com with the Wokwi arduino emulator, it is easy to do the changes, add input devices as well. To create a COM port You just need to have a Serial.begin(9600); Serial.println("Text message"); you will be able to see the virtual ...


Top 50 recent answers are included