Timeline for State machine problem
Current License: CC BY-SA 4.0
11 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Dec 25, 2021 at 19:41 | comment | added | Juraj♦ | yes it is possible to always take the value, add it to total and reset. I don't know how fast the value increments in your project. using byte is good because the operations are atomic and don't require to block interrupts. but using larger type allows spending more time in loop without checking the counter and that helps if you do networking. | |
Dec 25, 2021 at 17:16 | comment | added | Zaffresky | @Juraj I suppose you are talking about trigger counter being declared as type byte. Since in the state 2, the trigger will be decremented so I thought the count wouldn't go as high as 255. But thinking about it now I assume that may happen | |
Dec 25, 2021 at 17:10 | vote | accept | Zaffresky | ||
Dec 25, 2021 at 17:09 | comment | added | Zaffresky | @SimSon I didn't know about enum but you are right. Need to learn it's usage | |
Dec 22, 2021 at 19:01 | comment | added | Sim Son |
triggerCounter is declared as byte , so it can't become negative. The statements triggerCounter-- and if(triggerCounter>0) are error prone and probably don't what you expect.
|
|
Dec 22, 2021 at 18:56 | comment | added | Sim Son |
You should have all code that is relevant for the state machine in the switch block. The TelnetStream.println() might be ok in thw loop() , but pulseCountNew=0 should be in case 4 .
|
|
Dec 22, 2021 at 18:52 | comment | added | Sim Son |
The code will have a mich better readability if you use makros or an enum for the state, so you can have something like case RESET: ...
|
|
Dec 22, 2021 at 16:44 | answer | added | Juraj♦ | timeline score: 0 | |
Dec 22, 2021 at 16:21 | comment | added | Juraj♦ |
do you have less than 255 readings in one batch? you use byte
|
|
Dec 22, 2021 at 15:53 | comment | added | jsotola |
The pulse count gets resets after 5 sec ... don't reset the counter ... refer to how millis() is used
|
|
Dec 22, 2021 at 15:23 | history | asked | Zaffresky | CC BY-SA 4.0 |