Created
February 27, 2015 01:57
-
-
Save krobro/f1c5afc23bfdc7484312 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Morse_Hello | |
// | |
// Use the LED to send out 'HELLO' in morse code. | |
// | |
// We use pin 13 as depending on the Arduino board | |
// (the Duinobot in our case), it has either: | |
// - a built-in LED or, | |
// - a built-in resistor so that you only need to add an LED. | |
// | |
// NOTES: | |
// - The Duinobot has an LED so we do not have to add anything. | |
// - See http://www.arduino.cc/en/Tutorial/Blink for the original | |
// tutorial. | |
// | |
int dot = 250; | |
int dash = 3*dot; // a dash is equal to 3 times a dot ('*' means multiply) | |
int ledPin = 13; // on board LED connected to digital pin 13 | |
// | |
// show_a_dot | |
// | |
// Procedure to do all the work of blinking a dot | |
// | |
void show_a_dot() | |
{ | |
digitalWrite(ledPin, HIGH); // sets the LED on | |
delay(dot); // waits for a dot | |
digitalWrite(ledPin, LOW); // sets the LED off | |
delay(dot); // waits 3 dots | |
} | |
// | |
// show_a_dash | |
// | |
// Procedure to do all the work of blinking a dash | |
// | |
void show_a_dash() | |
{ | |
digitalWrite(ledPin, HIGH); // sets the LED on | |
delay(dash); // waits for a dot | |
digitalWrite(ledPin, LOW); // sets the LED off | |
delay(dot); // waits again for a dot | |
} | |
void setup() // run once, when the sketch starts | |
{ | |
pinMode(ledPin, OUTPUT); // sets the digital pin as output | |
} | |
void loop() // run over and over again | |
{ | |
// We are going to say 'HELLO' in morse code | |
// H | |
show_a_dot(); | |
show_a_dot(); | |
show_a_dot(); | |
show_a_dot(); | |
delay (2*dot); | |
// E | |
show_a_dot(); | |
delay (2*dot); | |
// L | |
show_a_dot(); | |
show_a_dash(); | |
show_a_dot(); | |
show_a_dot(); | |
delay (2*dot); | |
// L | |
show_a_dot(); | |
show_a_dash(); | |
show_a_dot(); | |
show_a_dot(); | |
delay (2*dot); | |
// O | |
show_a_dash(); | |
show_a_dash(); | |
show_a_dash(); | |
delay(6*dot); // waits between words | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment