2016-08-14 02:25:46 +00:00
|
|
|
/* Hamshield
|
|
|
|
* Example: HAMBot
|
|
|
|
* Simple DTMF controlled HAM Radio Robot. You will need
|
|
|
|
* seperate DTMF equipment as well as robot for this
|
|
|
|
* example.
|
|
|
|
* 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. After uploading
|
2016-08-27 19:53:37 +00:00
|
|
|
* this program to your Arduino, you can send commands from
|
2016-08-14 02:25:46 +00:00
|
|
|
* your DTMF equipment using the following list:
|
|
|
|
* '4' => turn robot left
|
|
|
|
* '6' => turn robot right
|
|
|
|
* '2' => move robot forward
|
|
|
|
* '5' => tell robot to send morse code identity
|
2016-08-17 19:24:36 +00:00
|
|
|
*/
|
2015-06-20 20:37:48 +00:00
|
|
|
|
|
|
|
#include <ArduinoRobot.h> // include the robot library
|
2016-04-14 02:12:06 +00:00
|
|
|
#include <HamShield.h>
|
2015-06-20 20:37:48 +00:00
|
|
|
#include <SPI.h>
|
|
|
|
|
2015-11-23 16:54:10 +00:00
|
|
|
#define PWM_PIN 3
|
|
|
|
#define RESET_PIN A3
|
|
|
|
#define SWITCH_PIN 2
|
|
|
|
|
2016-04-14 02:12:06 +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
|
|
|
Robot.begin();
|
2016-04-14 02:12:06 +00:00
|
|
|
|
2015-06-20 20:37:48 +00:00
|
|
|
radio.initialize();
|
2015-11-23 16:54:10 +00:00
|
|
|
radio.frequency(145510);
|
2015-06-20 20:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
if(radio.waitForDTMF()) { // wait for a received DTMF tone
|
|
|
|
uint8_t command = radio.getLastDTMFDigit(); // get the last DTMF tone sent
|
|
|
|
if(command == '4') { Robot.turn(-90); } // turn robot left
|
|
|
|
if(command == '6') { Robot.turn(90); } // turn robot right
|
|
|
|
if(command == '2') { Robot.motorsWrite(-255,-255); delay(500); Robot.motorsWrite(255, 255); } // move robot forward
|
|
|
|
if(command == '5') { // tell robot to send morse code identity
|
|
|
|
if(radio.waitForChannel()) { // wait for the user to release the transmit button
|
|
|
|
radio.setModeTransmit(); // turn on transmit mode
|
|
|
|
radio.morseOut("1ZZ9ZZ I AM HAMRADIO ROBOT"); // send morse code
|
|
|
|
radio.setModeReceive(); // go back to receive mode on radio
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|