Created
March 24, 2015 22:05
-
-
Save krobro/8a20ce106f913b2aaff6 to your computer and use it in GitHub Desktop.
Use the LED to send out 'HELLO' in morse code. This is an example solution to assignment 2 which utilizes procedures.
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_Hello2 | |
// | |
// Use the LED to send out 'HELLO' in morse code. | |
// This is an example solution to assignment 2. | |
// | |
// The Circuit: | |
// 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. | |
// | |
// Created: 3/18/2015 | |
// By: Chris Newton | |
// For: Makers 10: Robotics and Prototyping | |
// | |
int dot = 250; // time in milliseconds for a dot | |
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 dash | |
digitalWrite(ledPin, LOW); // sets the LED off | |
delay(dot); // waits again for a dot | |
} | |
// run once, when the sketch starts | |
void setup() | |
{ | |
pinMode(ledPin, OUTPUT); // sets the digital pin as output | |
} | |
// show the letter 'H' | |
void show_H () | |
{ | |
show_a_dot(); | |
show_a_dot(); | |
show_a_dot(); | |
show_a_dot(); | |
delay (2*dot); | |
} | |
void show_E () | |
{ | |
show_a_dot(); | |
delay (2*dot); | |
} | |
void show_L () | |
{ | |
show_a_dot(); | |
show_a_dash(); | |
show_a_dot(); | |
show_a_dot(); | |
delay (2*dot); | |
} | |
void show_O () | |
{ | |
show_a_dash(); | |
show_a_dash(); | |
show_a_dash(); | |
} | |
// show the word 'HELLO' | |
void show_HELLO () | |
{ | |
show_H(); | |
show_E(); | |
show_L(); | |
show_L(); | |
show_O(); | |
} | |
// run over and over again | |
void loop() | |
{ | |
// We are going to say 'HELLO' in morse code | |
show_HELLO(); | |
delay(6*dot); // waits between words | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment