Skip to content

Instantly share code, notes, and snippets.

@kw217
Created September 16, 2013 21:55
Show Gist options
  • Save kw217/6587129 to your computer and use it in GitHub Desktop.
Save kw217/6587129 to your computer and use it in GitHub Desktop.
Happy 10th birthday Aidan!
// Arduino Uno simulator with Morse Code.
// for Aidan's birthday party September 2013.
// http://gurunoia.lochan.org/blog/2013/09/arduino-cake/
// Keith Wansbrough <keithw@lochan.org>
// Dot length in milliseconds.
const int dot = 120;
// Pins of various LEDs.
const int pinpower = 3;
const int pinrx = 4;
const int pintx = 2;
const int pin13 = 5;
const int pinbuiltin = 13;
// Timings and counts for the program-load simulation.
const int xcount = 50;
const int xcount2 = 10;
const int xdelay = 20;
char* morse[] = {
".-", // A
"-...",
"-.-.",
"-..",
".",
"..-.",
"--.",
"....",
"..",
".---",
"-.-",
".-..",
"--",
"-.",
"---",
".--.",
"--.-",
".-.",
"...",
"-",
"..-",
"...-",
".--",
"-..-",
"-.--",
"--..", // Z
"-----", // 0
".----",
"..---",
"...--",
"....-",
".....",
"-....",
"--...",
"---..",
"----." // 9
};
// timing: dot=1, dash=3, gap=1, letter gap=3, word gap=7; typical dot = 60ms?
void flash(int pin, char* text) {
digitalWrite(pin, 0);
for (char*p = text; *p; p++) {
if (*p == ' ') {
delay(dot * 4);
} else if (*p >= 'A' && *p <= 'Z') {
flashChar(pin, morse[*p - 'A']);
delay(dot * 2);
} else if (*p >= 'a' && *p <= 'z') {
flashChar(pin, morse[*p - 'a']);
delay(dot * 2);
} else if (*p >= '0' && *p <= '9') {
flashChar(pin, morse[*p - '0' + 26]);
delay(dot * 2);
} else {
// do nothing!
}
}
}
void flashChar(int pin, char* code) {
for (char*p = code; *p; p++) {
if (*p == '.') {
digitalWrite(pin, 1);
delay(dot);
digitalWrite(pin, 0);
delay(dot);
} else if (*p == '-') {
digitalWrite(pin, 1);
delay(dot * 3);
digitalWrite(pin, 0);
delay(dot);
} else {
// do nothing!
}
}
}
void setup() {
pinMode(pinpower, OUTPUT);
pinMode(pinrx, OUTPUT);
pinMode(pintx, OUTPUT);
pinMode(pin13, OUTPUT);
pinMode(pinbuiltin, OUTPUT);
digitalWrite(pinbuiltin,1);
delay(500);
digitalWrite(pinbuiltin,0);
digitalWrite(pinpower,1);
delay(500);
digitalWrite(pinpower,0);
digitalWrite(pinrx,1);
delay(500);
digitalWrite(pinrx,0);
digitalWrite(pintx,1);
delay(500);
digitalWrite(pintx,0);
digitalWrite(pin13,1);
delay(500);
digitalWrite(pin13,0);
digitalWrite(pinbuiltin,1);
delay(500);
digitalWrite(pinbuiltin,0);
}
void loop() {
digitalWrite(pinpower, 1);
digitalWrite(pinrx, 0);
digitalWrite(pintx, 0);
digitalWrite(pin13, 0);
delay(500);
int i;
for (i = 0; i < xcount; i++) {
digitalWrite(pinrx, 1);
delay(xdelay);
digitalWrite(pinrx, 0);
delay(xdelay);
}
for (i = 0; i < xcount; i++) {
digitalWrite(pintx, 1);
delay(xdelay);
digitalWrite(pintx, 0);
delay(xdelay);
}
for (i = 0; i < xcount2; i++) {
digitalWrite(pinrx, 1);
delay(xdelay);
digitalWrite(pinrx, 0);
delay(xdelay);
}
for (i = 0; i < xcount2; i++) {
digitalWrite(pintx, 1);
delay(xdelay);
digitalWrite(pintx, 0);
delay(xdelay);
}
delay(2000);
flash(pin13, "Happy 10th Birthday Aidan");
delay(2000);
flash(pin13, "Happy 10th Birthday Aidan");
delay(10000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment