All -
This particular issue was discussed earlier and was shown as “SOLVED” - however I wanted to approach it from a new angle. It was originally posted as “Reading a tipping bucket rain gauge”.
I posted this earlier today … and it was classified as “SOLVED”, so I am reposting it as a new topic. Sorry for the confusion.
The project I am creating reads the revolutions of a water wheel over a period of time. It uses a Hall sensor and monitors the High/Low state of a digital pin on an MKR1000 board. There are two “timers” being used, one using “timer.set Interval” to call the action of a second timer which uses the “timer.setTimer” function to run every 100 millis and repeats 100 times. The second timer finishes its 100 cycles and returns to the first timer which then should send the data to the Blynk cloud. The program compiles just fine, however the revolution counter variable which is increased in the second timer function (setTimer) does not return its value to the calling function (set.Interval).
In the original “Tipping Bucket” topic …
The comment from Pavel is the same logic I am considering.
I am considering using the timer.setTimer" function from the SimpleTimer library because it allows me to set the timer to repeat every “d” millis for “n” times.
I am including the code snippet from Arduino.
int setTimer(long d, timer_callback f, int n)
Call function f every d milliseconds for n times. The callback function must be declared as void f(). After f has been called the specified number of times, the interval is deleted, therefore the value timerId is no longer valid.
void repeatMeFiveTimes() {
// do something
}
timerId = timer.setTimer(1000, repeatMeFiveTimes, 5);
So my first question is:
Does the Blynk Timer support “timer.setTimer”? I know it supports “timer.setInterval”, because most every timer has that function to create the delay in transferring data.
And if so … I am perplexed that the global variables I have in the sketch do not maintain their values when I exit the set.Timer function.
Second question - Does the “timer.setTimer” function clear the variables that have been modified within that function when it ends its “repeat cycles”? They are definitely global variables called in the beginning of the sketch outside of any function including setup(().
Finally -
I saw that the last comment from the old topic was to use an Interrupt …
I just though that the second timer using a combination of set.Interval and set.Timer function would be an easier approach.
Environment -
Mac oS Sierra 10.12.6
Arduino 1.8.3
Blank 2.10.1
MKR1000 Board
Thanks for any comments or suggestions.
Jim