/* * Arduino Morse Code - Hello World * Sends your message for forever. * Useful is you ever get stuck in earth orbit. * * Kyle Vice - Making Things Interact - Spring 2009 * Project 2 * * Jan 26, 2009 * Changed to "Hello World" using morse code * Moved to more robust parsing of messages using array as message source * * * Jan 22, 2009 * S-O-S using morse code * * */ int ledPin[] = {2,4,6}; //Which pin(s) are LEDs on? /* Generic Message Syntax: 0=letter break (we're moving on to another letter) 1=short (Dit) 2=long (Dah) 3=space ( ) int message[] = {1,1,1,0,2,2,2,0,1,1,1}; //SOS */ int message[] = {1,1,1,1,0,1,0,1,2,1,1,0,1,2,1,1,0,2,2,2,3,1,2,2,0,2,2,2,0,1,2,1,0,1,2,1,1,0,2,1,1}; //Hello World int loopCount = 0; //How many times have we looped? int shortSignal = 300; //How long is a short signal? int longSignal = 900; //How long is a long signal? int betweenLetters = 900; //How long to wait between letters int betweenWords = 2100; //How long to wait between words (space) int betweenTransmits = 10000; //Wait between transmissions void setup() { for(int j=0; j<3; j++) { pinMode(ledPin[j],OUTPUT); } } void loop() { if(loopCount < sizeof(message)/sizeof(int)) { //Loop through each part of message switch(message[loopCount]) { case 0: //0 = Letter Ending delay(betweenLetters); break; case 1: //1 = "Dit" case 2: //2 = "Dah" for(int j=0; j<3; j++) { digitalWrite(ledPin[j], HIGH); //Turn all of the lights on } if(message[loopCount] == 1) { //Keep the lights on. 1 for short wait, 2 for long wait. delay(shortSignal); } else { delay(longSignal); } for(int j=0; j<3; j++) { digitalWrite(ledPin[j], LOW); //Turn the lights off. } break; case 3: //3 = " " delay(betweenWords); break; } delay(shortSignal); loopCount++; //Increment the loop counter, move on to next part of message } else { delay(betweenTransmits); //Wait for amount of time in order to send message again loopCount = 0; //Move to front of message to re-send } }