What is best way to deal with button timing issue?
Ragtop
Posts: 406
I have a GPS data logger program that has a long loop with a waitcnt of 4 seconds between writes to a kml file. I use a button to start and stop recording of the kml file.
I have been using a separate cog to check the state of the button pin so that it doesn't have to be pressed at the exact time it goes back through the repeat loop.
I am sure there is a better way people are doing this, but couldn't find anything like this in the labs.
I want to add an accelerometer and need to free up a cog. I was thinking counters might could be used, but the counter examples are over my head.
I have been using a separate cog to check the state of the button pin so that it doesn't have to be pressed at the exact time it goes back through the repeat loop.
PUB InitButton cognew(button(@buttonpressed), @stack) Pub button(bp) dira[8]~ long[bp] := 0 repeat if ina[8] == 1 'stores a button press until an action is done in main program to remove timing issues. long[bp] := 1
I am sure there is a better way people are doing this, but couldn't find anything like this in the labs.
I want to add an accelerometer and need to free up a cog. I was thinking counters might could be used, but the counter examples are over my head.
Comments
The repeat-loop will run pretty fast and check very often if the elapsed time is more than
a value you can adjust. If elapsed time is more than log the data else don't store data
This way you can slow down the execution of a lot of things while your main loop is still running fast
best regards
Stefan