Description
Use the Arduino to let a Light Emitting Diode (LED) blink according to a morse code.
If one would include a switch and a battery, then the device could to transmit a preset message to the person pressing the switch. Unfortunately we didn’t get a switch or button with the kit.
Any input text can be transformed to morse code using the website: http://morsecode.scphillips.com/jtranslator.html
Components Used
Green LED
Resistor 220 Ohm
Arduino Code
// Morse Code Blinking // Letting a LED blink according to a morese code // Code adapted by Kilian Moser, 08/31/2011 // Acknowledgements: // Original morse code found at: http://www.maxkpage.com/blog/arduino-fun-with-leds-blink-morse-code/ // Text to Morse transformer foudn at: http://morsecode.scphillips.com/jtranslator.html // The morse code the LED will blink for, in this case 'hello world' char morse_code[] = ".... . .-.. .-.. --- .-- --- .-. .-.. -.."; // constants won't change. // set pin numbers: const int ledPin = 5; // the number of the LED pin const int short_interval = 100; // interval at which to blink (milliseconds) const int long_interval = 500; // interval at which to blink (milliseconds) const int space_interval = 300; // interval at which to blink (milliseconds) const int phrase_end_interval = 5000; // interval at which to blink (milliseconds) // Variables that will change: int ledState = LOW; // ledState used to set the LED int letterSpot = 0; // Current letter you are testing in the morse code void setup() { // set the digital pin as output: pinMode(ledPin, OUTPUT); } void loop() { if(morse_code[letterSpot] == '.') { // if the LED is off turn it on: if (ledState == LOW) ledState = HIGH; digitalWrite(ledPin, ledState); delay(short_interval); } else if (morse_code[letterSpot] == '-') { // if the LED is off turn it on: if (ledState == LOW) ledState = HIGH; digitalWrite(ledPin, ledState); delay(long_interval); } else { //Space in the morse code letterSpot++; delay(space_interval); } if (ledState == HIGH) { // if the LED is on turn it off: ledState = LOW; digitalWrite(ledPin, ledState); } if (letterSpot < sizeof(morse_code) - 1) { // Move to the next letter in the morse code, unless you are at the end letterSpot++; } else { // Long pause at the end of the phrase before it starts over again letterSpot = 0; delay(phrase_end_interval); } // Small pause delay(short_interval); }
Photo