/* XRF Arduino Test Sketch - Beacon * * Full details of this example: http://bit.ly/sPPN8a * * Simple sketch to check the XRF radio modules are working. * Broadcasts the letter "H" (Hello) every 5 seconds. * * I'm using 2 x XRF modules and 2 x Xbee sheilds from Ciseco, and an * Arduino Uno and Arduino Ethernet. The default XRF baud rate in 9600. * * This sketch (1 of 2) is running on the Arduino Uno, which has a * built in LED on pin 13. A piezo beeper was connected to pin 7 for * audiable acknowledgment of activity. * * Created 4 Dec 2011 * by Mark Sweeting - www.sweeting.org/mark */ int LEDPin = 13; // built in to the Uno PCB int XbeeEnable = 8; // powers up the XRF when using the Xbee shield int BuzzerPin = 7; int BuzzerTone = 6000; unsigned long lastBeaconTime = 0; unsigned long nowTime = 0; unsigned long LEDTime = 0; int beaconInterval = 2000; int LEDPeriod = 300; void setup() { pinMode(LEDPin, OUTPUT); pinMode(XbeeEnable, OUTPUT); // Turn XRF on digitalWrite(XbeeEnable, HIGH); Serial.begin(9600); } void loop() { // Get the current time since power-up nowTime = millis(); // Send the letter 'H' ("Hello") on the serial line every few // seconds if((nowTime - lastBeaconTime) > beaconInterval) { Serial.print("H"); lastBeaconTime = nowTime; } // If we receive the letter 'K' (for "OK"), then turn the LED on // for a moment and beep the buzzer if(Serial.available() > 0) { if(Serial.read() == 'K') { LEDTime = nowTime; } } if(LEDTime) { digitalWrite(LEDPin, HIGH); tone(BuzzerPin, BuzzerTone); // Turn LED off after a short period if((nowTime - LEDTime) > LEDPeriod) { LEDTime = 0; digitalWrite(LEDPin, LOW); noTone(BuzzerPin); } } }