// AM broadcasting using arduino // Based on the code from WWW.JONNYBLANCH.WEBS.COM, which was originaly broken const long period_broadcast=8; //period of shortest broadcast (256 port changes) #define LENGTH_DIT 64 //number of period_broadcasts in one 'dit', //all other lengths are scaled from this //Broadcasts on 1337 kHz // You should put some piece of wire as antenna in digital port 8. // The experiments at www.mateslab.com.ar show us that a 20cm cable can be tuned with a radio from 2,5 meters. With a 50cm antena you can tune it from 5 meters. const int length_dit=LENGTH_DIT; //number of periods for dit const int pause_dit=LENGTH_DIT; //pause after dit const int length_dah=3*LENGTH_DIT; //number of persots for dah const int pause_dah=LENGTH_DIT; //pause after dah const int length_pause=7*LENGTH_DIT; //pause between words // ### INC ### Increment Register (reg = reg + 1) #define ASM_INC(reg) asm volatile ("inc %0" : "=r" (reg) : "0" (reg)) void setup() { Serial.begin(9600); DDRB=0xFF; //Port B all outputs } void loop() { say_string("HELLO WORD"); } // Outputs a dot (.) void dit(void) { for(int i=0; i <= length_dit; i++) // now is 64 broadcast(period_broadcast); } // Output a dash (-) void dah(void) { for(int i=0; i <= length_dah; i++) // now is 64*3 broadcast(period_broadcast); } // Short pause between chars void char_pause(void) { for(int i=0; i <= length_dit; i++) // now is 64 dontbroadcast(period_broadcast); } // Long pause between words void word_pause(void) { for(int i=0; i <= length_pause; i++) // now is 64 dontbroadcast(period_broadcast); } // This send something to the air void broadcast(int N_cycles) { unsigned int portvalue; for (int i=0;i < N_cycles; i++) { do { PORTB=portvalue; ASM_INC(portvalue); } while(portvalue<255); } } // This do not send anything to the air void dontbroadcast(int N_cycles) { unsigned int portvalue; PORTB=0x00; for (int i=0;i < N_cycles; i++) { do { ASM_INC(portvalue); //add some assembly No OPerations to keep timing the same asm volatile ("NOP"); } while(portvalue < 255); } } // Code based on http://silveiraneto.net/2009/02/28/morse-code-translator-with-arduino/, but changed to send chars over the air. char * morsecode[] = { "-----", // 0 ".----", // 1 "..---", // 2 "...--", // 3 "....-", // 4 ".....", // 5 "-....", // 6 "--...", // 7 "---..", // 8 "----.", // 9 "---...", // : "-.-.-.", // ; "", // < (there's no morse for this simbol) "-...-", // = "", // > (there's no morse for this simbol) "..--..", // ? ".--._.", // @ ".-", // A "-...", // B "-.-.", // C "-..", // D ".", // E "..-.", // F "--.", // G "....", // H "..", // I ".---", // J "-.-", // K ".-..", // L "--", // M "-.", // N "---", // O ".--.", // P "--.-", // Q ".-.", // R "...", // S "-", // T "..-", // U "...-", // V ".--", // W "-..-", // X "-.--", // Y "--.." // Z }; void send_morse_char(char * msg){ int index = 0; while(msg[index]!='\0'){ // Serial.print(msg[index]); // say a dash if(msg[index]=='-'){ dah(); char_pause(); } // say a dot if(msg[index]=='.'){ dit(); char_pause(); } index++; } } void say_char(char letter){ if((letter>='0')&&(letter<='Z')&&(letter!='<')&&(letter!='>')){ // Serial.print(morsecode[letter-'0']); // Serial.print(' '); send_morse_char(morsecode[letter-'0']); } else { if(letter==' '){ // Serial.print(" \\ "); word_pause(); }else{ // Serial.print("X"); } } // Serial.println(""); } void say_string(char * asciimsg){ int index = 0; char charac; char ascii_char; charac = asciimsg[index]; while(charac!='\0'){ say_char(charac); // Serial.print(charac); charac = asciimsg[++index]; } word_pause(); }