Posted 05 October 2013 - 01:44 AM
Title: Loop counter going nuts
Hey people! I have a small problem here that needs help.
So, a guy made a program to keep track of 8 redstone energy cells (the amount of energy on them, with openPeripherals), and automatically turn the energy production lines for each of them on or off. With his permission (he asked his subscribers, actually), I got his code and developed it further, adding more functions, like a display monitor, colored bars, override buttons, etc. I made the program to cycle again if a specific number of seconds have passed (the "frequency" variable) or if a button has been touched. At the end of the loop, there is a bit of code made to keep track of how many cycles have passed, and reset the counter once a specific value has been reached. That part is used so the program refreshes the tables containing older energy values after a certain number of cycles. And that data is used on a graph.
Here is the code: http://pastebin.com/A95R2RVL
Now, the problem. As you can probably see, the counter is supposed to count up (or reset) after the program makes a full cycle. The program will finish cycling if either 2 seconds have passed or a touch in the monitor or terminal is detected. The thing runs fine, until the first click. Then, the counter goes completely crazy, and starts doing weird things, like waiting 2 seconds before increasing the counter by 2, therefore the program starts looping faster, in a weird way. A few more clicks, and it gets worse. I tried various things, but the only thing that seemed to work was to put a sleep(1) in the end of the code and reduce frequency by 1. However, this method also creates an input lag that drives me crazy. What I'm looking for is a way to solve this issue while avoiding input lag.
Any help is much necessary and appreciated.
Tanks in advance.
Hey people! I have a small problem here that needs help.
So, a guy made a program to keep track of 8 redstone energy cells (the amount of energy on them, with openPeripherals), and automatically turn the energy production lines for each of them on or off. With his permission (he asked his subscribers, actually), I got his code and developed it further, adding more functions, like a display monitor, colored bars, override buttons, etc. I made the program to cycle again if a specific number of seconds have passed (the "frequency" variable) or if a button has been touched. At the end of the loop, there is a bit of code made to keep track of how many cycles have passed, and reset the counter once a specific value has been reached. That part is used so the program refreshes the tables containing older energy values after a certain number of cycles. And that data is used on a graph.
Here is the code: http://pastebin.com/A95R2RVL
Now, the problem. As you can probably see, the counter is supposed to count up (or reset) after the program makes a full cycle. The program will finish cycling if either 2 seconds have passed or a touch in the monitor or terminal is detected. The thing runs fine, until the first click. Then, the counter goes completely crazy, and starts doing weird things, like waiting 2 seconds before increasing the counter by 2, therefore the program starts looping faster, in a weird way. A few more clicks, and it gets worse. I tried various things, but the only thing that seemed to work was to put a sleep(1) in the end of the code and reduce frequency by 1. However, this method also creates an input lag that drives me crazy. What I'm looking for is a way to solve this issue while avoiding input lag.
Any help is much necessary and appreciated.
Tanks in advance.