
RP6 ROBOT SYSTEM - 4. Programming the RP6
We are using Stopwatch1 and Stopwatch2 here, which get started at lines 9 and 10
respectively. Afterwards the Stopwatch counters are running. The infinite loop (at lines
16 up to 37) constantly checks, whether the Stopwatches exceed a predefined level.
The if-condition in line 19 for example controls the running light and checks, whether
the stopwatch has been running for at least 100ms since the last reset to zero. As
soon as this gets true, the next LED will be activated and the counter will be reset to
zero (line 25) in order to wait for another 100ms. The same procedure is used for the
other counter, which in contrast checks for intervals of 1000ms, respectively 1 second.
You will find a slightly extended version of this program on the CD. It is just a small
example, but you may build rather complex systems with the Stopwatches and start
or stop them at certain events ...
The sample program on the CD also includes the running light and the counter (we
have even 3 counters in this program...), but they are implemented in separate func-
tions, which will be called from the infinite loop.
Seperating program code in functions will help you to keep an overview of complex
programs and simplifies reusing program modules by Copy&Paste. E.g. the running
light code can be used in other programs without big changes...
Several macros have been implemented for stopwatch control.
startStopwatchX()
starts stopwatch X. The command does not reset the Stopwatch and it will continue
incrementing from the last counter level.
Examples:
startStopwatch1();
startStopwatch2();
stopStopwatchX()
stops Stopwatch X.
Examples:
stopStopwatch2();
stopStopwatch1();
uint8_t isStopwatchXRunning()
returns if stopwatch X is running.
Example:
if(!isStopwatch2Running) {
// Stopwatch has been deactivated, so you may do sth. againt this...
}
setStopwatchX(uint16_t preset)
- 85 -