General FoxHunt example sketch fixups. Added code comments to aid understanding. Added a number of serial prints so you can see what it's doing. Moved the long wait inside the if->transmit block so we don't wait a long time if the channel was busy.
This commit is contained in:
parent
ae0dacac77
commit
daa4befe2c
|
@ -1,13 +1,16 @@
|
||||||
/* Hamshield
|
/* Hamshield
|
||||||
* Example: Fox Hunt
|
* Example: Fox Hunt
|
||||||
* Plays a one minute tone at 10-13 minute intervals. Script
|
*
|
||||||
* will check to see if the channel is clear before it will
|
* Plays a one minute tone, then IDs at 10-13 minute intervals. Script
|
||||||
* transmit.
|
* will check to see if the channel is clear before it will transmit.
|
||||||
|
*
|
||||||
* Connect the HamShield to your Arduino. Screw the antenna
|
* Connect the HamShield to your Arduino. Screw the antenna
|
||||||
* into the HamShield RF jack. Connect the Arduino to wall
|
* into the HamShield RF jack. Connect the Arduino to wall
|
||||||
* power and then to your computer via USB. To test, set a
|
* power and then to your computer via USB. After uploading
|
||||||
* HandyTalkie to 438MHz. You should hear a one-minute tone
|
* this program to your Arduino, open the Serial Monitor to
|
||||||
* followed by a callsign every 10-13 minutes.
|
* monitor the status of the beacon. To test, set a HandyTalkie
|
||||||
|
* to 438MHz. You should hear a one-minute tone followed by
|
||||||
|
* a callsign every 10-13 minutes.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <HamShield.h>
|
#include <HamShield.h>
|
||||||
|
@ -36,24 +39,64 @@ void setup() {
|
||||||
pinMode(RESET_PIN, OUTPUT);
|
pinMode(RESET_PIN, OUTPUT);
|
||||||
digitalWrite(RESET_PIN, HIGH);
|
digitalWrite(RESET_PIN, HIGH);
|
||||||
|
|
||||||
|
// Set up the serial port at 9600 Baud
|
||||||
|
Serial.begin(9600);
|
||||||
|
|
||||||
|
// Send a quick serial string
|
||||||
|
Serial.println("HamShield FoxHunt Example Sketch");
|
||||||
|
|
||||||
|
// Query the HamShield for status information
|
||||||
|
Serial.print("Radio status: ");
|
||||||
|
int result = radio.testConnection();
|
||||||
|
Serial.println(result, DEC);
|
||||||
|
|
||||||
|
// Tell the HamShield to start up
|
||||||
radio.initialize();
|
radio.initialize();
|
||||||
|
|
||||||
|
// Set the transmit power level (0-8)
|
||||||
radio.setRfPower(0);
|
radio.setRfPower(0);
|
||||||
|
|
||||||
|
// Set the morse code characteristics
|
||||||
|
radio.setMorseFreq(600);
|
||||||
|
radio.setMorseDotMillis(100);
|
||||||
|
|
||||||
|
// Configure the HamShield to operate on 438.000Mhz
|
||||||
radio.frequency(438000);
|
radio.frequency(438000);
|
||||||
radio.setModeReceive();
|
|
||||||
|
Serial.println("Radio configured.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if(radio.waitForChannel(30000,2000, -90)) { // wait for a clear channel, abort after 30 seconds, wait 2 seconds of dead air for breakers
|
// We'll wait up to 30 seconds for a clear channel, requiring that the channel is clear for 2 seconds before we transmit
|
||||||
radio.setModeTransmit(); // turn on transmit mode
|
if (radio.waitForChannel(30000,2000, -90)) {
|
||||||
tone(PWM_PIN, 1000, TRANSMITLENGTH); // play a long solid tone
|
// If we get here, the channel is clear. Let's print the RSSI to the serial port as well.
|
||||||
|
Serial.print("Signal is clear, RSSI: ");
|
||||||
|
Serial.println(radio.readRSSI());
|
||||||
|
|
||||||
|
// Set the HamShield to TX
|
||||||
|
Serial.print("Transmitting...");
|
||||||
|
radio.setModeTransmit();
|
||||||
|
|
||||||
|
// Generate a 600Hz tone for TRANSMITLENGTH time
|
||||||
|
tone(PWM_PIN, 600, TRANSMITLENGTH);
|
||||||
delay(TRANSMITLENGTH);
|
delay(TRANSMITLENGTH);
|
||||||
radio.morseOut(" 1ZZ9ZZ/B FOXHUNT"); // identify the fox hunt transmitter
|
|
||||||
radio.setModeReceive(); // turn off the transmit mode
|
// Identify the transmitter
|
||||||
|
radio.morseOut(" CALLSIGN FOXHUNT");
|
||||||
|
|
||||||
|
// Set the HamShield back to RX
|
||||||
|
radio.setModeReceive();
|
||||||
|
Serial.println("Done.");
|
||||||
|
|
||||||
|
// Wait for INTERLVAL + some random minutes before transmitting again
|
||||||
|
waitMinute(INTERVAL + random(0,RANDOMCHANCE));
|
||||||
}
|
}
|
||||||
waitMinute(INTERVAL + random(0,RANDOMCHANCE)); // wait before transmitting, randomly
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// a function so we can wait by minutes
|
// a function so we can wait by minutes
|
||||||
void waitMinute(unsigned long period) {
|
void waitMinute(unsigned long period) {
|
||||||
|
Serial.print("Waiting for ");
|
||||||
|
Serial.print(period, DEC);
|
||||||
|
Serial.println(" minutes.");
|
||||||
delay(period * 60 * 1000);
|
delay(period * 60 * 1000);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue