/ AM_Radio_Morse / AM_Radio_Morse.ino
AM_Radio_Morse.ino
1 // SPDX-FileCopyrightText: 2018 John Edgar Park for Adafruit Industries 2 // 3 // SPDX-License-Identifier: MIT 4 5 // For Adafruit_AMRadio library -- Morse code transmits on AM 540. 6 // Connect antenna (40" wire) to pin A0 and GND 7 // RANGE IS LIMITED TO A FEW FEET 8 // Morse "dot" key is a contact switch connected to D2 and GND 9 // "Dash" key is switch connected to D0 and GND 10 // Adapted from Phil Burgess's AMRadio sketch 11 12 #include <Adafruit_AMRadio.h> 13 14 Adafruit_AMRadio radio; 15 16 const int buttonDotPin = 2; //pushbutton pin for dit 17 const int buttonDashPin = 0; //pushbutton pin for dah 18 const int ledPin = 13; //to light the onboard LED 19 20 int buttonDotState = 0; //to store button state 21 int buttonDashState = 0; 22 23 //Morse varaiblas 24 const int PITCH = 680; 25 const int DOT = 100; //duration of short dot in millis 26 const int DASH = DOT * 3; 27 const int GAP = DOT; 28 29 30 void setup() { 31 pinMode(ledPin, OUTPUT); 32 pinMode(buttonDotPin, INPUT_PULLUP); 33 pinMode(buttonDashPin, INPUT_PULLUP); 34 35 radio.begin(540000); //start radio object, transmits at 540MHz AM 36 } 37 38 39 void loop() { 40 buttonDotState = digitalRead(buttonDotPin); 41 buttonDashState = digitalRead(buttonDashPin); 42 43 if (buttonDotState == HIGH) { // not pressed 44 digitalWrite(ledPin, LOW); // light is off 45 } 46 else { // pressed 47 digitalWrite(ledPin, HIGH); // light on 48 radio.tone(PITCH, DOT); 49 delay(GAP); 50 } 51 if (buttonDashState == HIGH) { // not pressed 52 digitalWrite(ledPin, LOW); // light is off 53 } 54 else { // pressed 55 digitalWrite(ledPin, HIGH); // light on 56 radio.tone(PITCH, DASH); 57 delay(GAP); 58 } 59 60 delay(15); 61 }