Last active
September 1, 2016 02:53
-
-
Save nbrew/683d316f11eb697be567f47366cb805f to your computer and use it in GitHub Desktop.
Arduino SOS (Work in Progress)
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
/** | |
* SOS for a single LED | |
* | |
* @author Nathan Hyde | |
* @version 2016-08-31 | |
*/ | |
// Define the Pins | |
int LED=13; // use the arduino's built-in led on pin 13 | |
int DOT_DELAY = 100; // short delay ms | |
int DASH_DELAY = 300; // long delay ms | |
int PAUSE_DELAY = 500; // character delay in ms | |
void setup() { | |
pinMode(LED, OUTPUT); // set the LED pin to an output | |
} | |
void loop() { | |
SOS(LED); | |
} | |
/** | |
* Flashes a single LED for the sequence of dots and dashes representing S-O-S | |
* | |
* @param led - The LED to adjust | |
*/ | |
void SOS(int led) { | |
S(led); | |
O(led); | |
S(led); | |
delay(PAUSE_DELAY); | |
} | |
/** | |
* Flashes an LED on and off for DOT_DELAY ms. | |
* | |
* @param led - The LED to adjust | |
*/ | |
void Dot(int led) { | |
LedOnOff(led, DOT_DELAY); | |
} | |
/** | |
* Flashes an LED on and off for DASH_DELAY ms. | |
* | |
* @param led - The LED to adjust | |
*/ | |
void Dash(int led) { | |
LedOnOff(led, DASH_DELAY); | |
} | |
/** | |
* Flashes an LED on and off for the given delay. | |
* | |
* @param led - The LED to adjust | |
* @param delay_ms - Number of miliseconds to wait between turning the LED on and off. | |
*/ | |
void LedOnOff(int led, int delay_ms) { | |
LedOff(led); | |
delay(delay_ms); | |
digitalWrite(led, HIGH); | |
delay(delay_ms); | |
} | |
void LedOff(int led) { | |
digitalWrite(led, LOW); | |
} | |
void S(int led) { | |
for(int i=0; i < 3; i++) { | |
Dot(led); | |
} | |
LedOff(led); | |
} | |
void O(int led) { | |
for(int i=0; i < 3; i++) { | |
Dash(led); | |
} | |
LedOff(led); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment