// The main loop:
while (TRUE) {
// Sample the pot meter value
ADC_SAMPLE_SINGLE();
ADC_GET_SAMPLE_8(ledDutyCycle);
// If the dimmer value has changed by more than 1, then
// transmit the new value automatically
// Transmit also when the S2 button is pressed
dimmerDifference = (ledDutyCycle & 0xFF) - pTxBuffer[0];
if((ABS(dimmerDifference)>2)||(JOYSTICK_CENTER_PRESSED())) {
pTxBuffer[0] = ledDutyCycle;
if (basicRfSendPacket(&rfTxInfo)) {
// OK. Blink the yellow LED
SET_YLED();
halWait(50000);
CLR_YLED();
} else {
// No acknowledgment received -> Blink the red LED
SET_RLED();
halWait(50000);
CLR_RLED();
}
}
}
Listing 2—Things are just as simple on the transmission side. This excerpt from the same file as Listing 1 shows you how to respond to events by transmitting information using the basicRfSendPacket function provided in the RF library.