variables
{
message 0x1A0 msg; // initializes a message with the
// name msg and identifier 0x1A0
msTimer myTimer; // timer with millisecond resolution
int running; // memorizes the first keypress to
// bypass the key repeat
int counter; // message counter
}
on timer myTimer
{
if (keypressed()) // if key is pressed ...
{
counter++; // increment counter by 1
msg.byte(0) = counter; // write the counter reading
// into the 1. byte of the message
output(msg); // send the message to the bus
setTimer(myTimer, 100); // set a timer to 100 ms
}
else // if key is released...
{
running = 0; // wait until new keypress
}
}
on key 'r'
{
if (running == 1) return; // inhibit key repeat
setTimer (myTimer,0); // start timer
running = 1; // memorize of first keypress
}