2016-08-13 21:05:19 +00:00
|
|
|
/* Hamshield
|
|
|
|
* 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
|
|
|
|
* transmit.
|
|
|
|
* Connect the HamShield to your Arduino. Screw the antenna
|
|
|
|
* into the HamShield RF jack. Connect the Arduino to wall power and then
|
|
|
|
* to your computer via USB. To test, set a HandyTalkie
|
|
|
|
* to 438MHz. You should hear a one-minute tone every 10-13 minutes.
|
|
|
|
*/
|
2015-06-20 20:37:48 +00:00
|
|
|
|
2016-03-25 03:31:17 +00:00
|
|
|
#include <HamShield.h>
|
2015-06-20 20:37:48 +00:00
|
|
|
|
2015-11-23 16:54:10 +00:00
|
|
|
#define PWM_PIN 3
|
|
|
|
#define RESET_PIN A3
|
|
|
|
#define SWITCH_PIN 2
|
|
|
|
|
2016-06-05 20:01:39 +00:00
|
|
|
// In milliseconds
|
|
|
|
#define TRANSMITLENGTH 60000
|
|
|
|
// In minutes
|
2015-06-20 20:37:48 +00:00
|
|
|
#define INTERVAL 10
|
|
|
|
#define RANDOMCHANCE 3
|
|
|
|
|
2016-03-25 03:31:17 +00:00
|
|
|
HamShield radio;
|
2015-06-20 20:37:48 +00:00
|
|
|
|
2015-11-23 16:54:10 +00:00
|
|
|
void setup() {
|
|
|
|
// NOTE: if not using PWM out, it should be held low to avoid tx noise
|
|
|
|
pinMode(PWM_PIN, OUTPUT);
|
|
|
|
digitalWrite(PWM_PIN, LOW);
|
|
|
|
|
|
|
|
// prep the switch
|
|
|
|
pinMode(SWITCH_PIN, INPUT_PULLUP);
|
|
|
|
|
|
|
|
// set up the reset control pin
|
|
|
|
pinMode(RESET_PIN, OUTPUT);
|
|
|
|
digitalWrite(RESET_PIN, HIGH);
|
|
|
|
|
2015-06-20 20:37:48 +00:00
|
|
|
radio.initialize();
|
2016-06-05 20:01:39 +00:00
|
|
|
radio.setRfPower(0);
|
|
|
|
radio.frequency(438000);
|
2015-06-20 20:37:48 +00:00
|
|
|
radio.setModeReceive();
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
2016-06-05 20:01:39 +00:00
|
|
|
if(radio.waitForChannel(30000,2000, -90)) { // wait for a clear channel, abort after 30 seconds, wait 2 seconds of dead air for breakers
|
|
|
|
radio.setModeTransmit(); // turn on transmit mode
|
|
|
|
tone(PWM_PIN, 1000, TRANSMITLENGTH); // play a long solid tone
|
|
|
|
delay(TRANSMITLENGTH);
|
|
|
|
radio.morseOut(" 1ZZ9ZZ/B FOXHUNT"); // identify the fox hunt transmitter
|
|
|
|
radio.setModeReceive(); // turn off the transmit mode
|
|
|
|
}
|
|
|
|
waitMinute(INTERVAL + random(0,RANDOMCHANCE)); // wait before transmitting, randomly
|
2015-06-20 20:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// a function so we can wait by minutes
|
2016-06-05 20:01:39 +00:00
|
|
|
void waitMinute(unsigned long period) {
|
2015-06-20 20:37:48 +00:00
|
|
|
delay(period * 60 * 1000);
|
|
|
|
}
|