/* Radio Fox Tranmitter by Nathanael Wilson This transmits a long tone, followed by a call in morse code. It then waits an ammount of time then transmits it again. This transmits by connecting to a radio's ptt and mic input. */ #define tonehz 300 //the aproxamite frequency of the tones in hz, in reality it will be a tad lower. #define dit 64 //the length of the dit in milliseconds. The dah and pauses are derived from this. #define rest 60000 //the ammount of time between transmits in milliseconds #define longlength 15000 //length of long tone in milliseconds #define tx 11 //the pin of the board then keys the radio #define audio 12 //the pin of the board then outputs the audio int code[] = { 1, 1, 1, 0, 2, 2, 2, 0, 1, 1, 1, 0 }; // 1 id dih, 2 is dah, 0 is pause int codelength = sizeof(code) / 2; //Divide the length that the array responds with by 2. //Not sure why it returns 2 times the ammaount of info stored, but it does. int length; int duration; int note = 1000000 / tonehz; //converts the frquency into period void setup(){ //set the pins to output mode pinMode(tx, OUTPUT); pinMode(audio, OUTPUT); pinMode(13, OUTPUT); //this is to see how the code looks with an led } void loop(){ digitalWrite(tx, HIGH); //starts the radio transmitting playtone(longlength); delay(250); playcode(); digitalWrite(tx, LOW); //Stops the radio's transmission delay(rest); } void playtone(int note_duration){ long elapsed_time = 0; if (note_duration > 0){ digitalWrite(13, HIGH); //See when it is making a tone on the led while (elapsed_time < note_duration){ digitalWrite(audio, HIGH); delayMicroseconds(note / 2); digitalWrite(audio, LOW); delayMicroseconds(note / 2); elapsed_time += note / 1000; } digitalWrite(13, LOW); } else{ //if it's a pause this will run delay(dit * 2); } } void playcode(){ for (int i=0; i < codelength; i++){ length = code[i]; if (length == 0){ //See if it's a pause duration = 0; } else if (length == 1){ //See if it's a dit duration = dit; } else if (length == 2){ //See if it's a dah duration = dit * 3; } playtone(duration); delay(dit); //makes a pause between sounds, otherwise each letter would be continuous. } }