Slight rearranging, and added comments to FM Beacon example sketch.

This commit is contained in:
Nigel Vander Houwen 2015-06-28 10:20:57 -07:00
parent 0126665e4c
commit 2d5deedf54
1 changed files with 41 additions and 17 deletions

View File

@ -1,44 +1,68 @@
/* /*
Morse Code Beacon Morse Code Beacon
Test beacon will transmit and wait 30 seconds. Test beacon will transmit and wait 30 seconds.
Beacon will check to see if the channel is clear before it will transmit. Beacon will check to see if the channel is clear before it will transmit.
*/ */
// Include the HamSheild and Wire (I2C) libraries
#include <HamShield.h> #include <HamShield.h>
#include <Wire.h> #include <Wire.h>
// Create a new instance of our HamSheild class, called 'radio'
HamShield radio; HamShield radio;
// Run our start up things here
void setup() { void setup() {
// Set up the serial port at 9600 Baud
Serial.begin(9600); Serial.begin(9600);
Serial.println("starting up..");
// Send a quick serial string
Serial.println("HamShield FM Beacon Example Sketch");
// Start the Wire (I2C) library
Wire.begin(); Wire.begin();
// Query the HamShield for status information
Serial.print("Radio status: "); Serial.print("Radio status: ");
int result = radio.testConnection(); int result = radio.testConnection();
Serial.println(result,DEC); Serial.println(result,DEC);
radio.initialize(); // setup radio
radio.frequency(446000); // set to 70 cm call frequency // Tell the HamShield to start up
Serial.println("Done with radio beacon setup."); radio.initialize();
// Configure the HamShield to transmit and recieve on 446.000MHz
radio.frequency(446000);
Serial.println("Radio Configured.");
} }
void loop() { void loop() {
if(radio.waitForChannel(30000,2000,-50)) { // wait up to 30 seconds for a clear channel, and then 2 seconds of empty channel // We'll wait up to 30 seconds for a clear channel, requiring that the channel is clear for 2 seconds before we transmit
Serial.println("Signal is clear -- Transmitting"); if (radio.waitForChannel(30000,2000,-50)) {
radio.setModeTransmit(); // turn on the transmitter // If we get here, the channel is clear. Let's print the RSSI to the serial port as well.
radio.morseOut("1ZZ9ZZ/B CN87 ARDUINO HAMSHIELD"); Serial.print("Signal is clear, RSSI: ");
radio.setModeReceive(); // turn off the transmitter (receive mode) Serial.println(radio.readRSSI());
Serial.print("TX Off");
// Start transmitting by putting the radio into transmit mode.
Serial.print("Transmitting... ");
radio.setModeTransmit();
// Send a message out in morse code
radio.morseOut("CALLSIGN LOCATOR ARDUINO HAMSHIELD");
// We're done sending the message, set the radio back into recieve mode.
radio.setModeReceive();
Serial.println("Done.");
// Wait 30 seconds before we send our beacon again.
delay(30000); delay(30000);
} else { } else {
// If we get here, the channel is busy. Let's also print out the RSSI.
Serial.print("The channel was busy. Waiting 10 seconds. RSSI: "); Serial.print("The channel was busy. Waiting 10 seconds. RSSI: ");
Serial.println(radio.readRSSI()); Serial.println(radio.readRSSI());
// Wait 10 seconds and check the channel again.
delay(10000); delay(10000);
} }
} }