User`s manual

RabbitFLEX User’s Manual www.rabbit.com 83
Note that as we iterate through the loop, we keep track of the switch, LED, and switch number that we are
on. Incrementing the switch_pressed and led pointers will make them point to the next member in
the respective group.
// Wait 50 ms to make sure the switch stays pressed (debouncing)
waitfor(DelayMs(50));
// Check if the switch is still pressed
if (flexDigIn(*switch_pressed) == 1) {
Now we begin switch debouncing. We wait 50 ms, and then check if the switch has been pressed again.
Note that switch_pressed indicates which pin has been pressed—this is one of the results from the
loop above. However, switch_pressed is a double pointer (Flex_IOPin **), whereas
flexDigIn() expects a single pointer (Flex_IOPin *). Therefore, we need to dereference
switch_pressed in the call to flexDigIn().
// Light the corresponding output LED
flexDigOut(*led, 0);
//
Play the tone
flexToneLoad(tones[switchnum], tone_len[switchnum], REPEAT_TONE);
while (1) {
// Wait for the switch to be released
waitfor(flexDigIn(*switch_pressed) == 0);
// Wait additional 200 ms
waitfor(DelayMs(200));
// If the switch is still released, then break out of the while loop
if (flexDigIn(*switch_pressed) == 0) {
// Turn the LED back off
flexDigOut(*led, 1);
break;
}
} // end of while loop
}
}
}
At this point, the code here is very similar to the debouncing code in the previous section. The only differ-
ences are the references to switch_pressed and led. Because those variables are now both double
pointers, we must dereference them when making calls to flexDigIn() and flexDigOut().
This section demonstrated how to use the grouping functionality in the RabbitFLEX API. The techniques
described in this chapter should now have given you a running start to implementing your own Rabbit-
FLEX applications.