Skip to content

Instantly share code, notes, and snippets.

@unruthless
Created February 2, 2013 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unruthless/4695954 to your computer and use it in GitHub Desktop.
Save unruthless/4695954 to your computer and use it in GitHub Desktop.
/*
Morsino
Flashes the morse code of the clicked letter.
This example code is in the public domain.
*/
const int ledPin = 13; // the number of the LED pin
const int buttonPin = 2; // the number of the pushbutton pin
void setup() {
pinMode(ledPin, OUTPUT); // initialize the digital pin as an output.
pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input.
}
// The length, in milliseconds, of one unit
const int UNIT = 500;
// Gap duration factors
const int DIT = 1;
const int DAH = 3;
const int ELEMENT_GAP = 1;
const int LETTER_GAP = 3;
const int WORD_GAP = 7;
// ITU Letters
// Kludge: to get around arduino's lack of a .length() function,
// the first item in each array is the number of elements for that character.
const int CHAR_A[] = { 2, DIT, DAH };
const int CHAR_B[] = { 4, DAH, DIT, DIT, DIT };
const int CHAR_C[] = { 4, DAH, DIT, DAH, DIT };
const int CHAR_D[] = { 3, DAH, DIT, DIT };
const int CHAR_E[] = { 1, DIT };
const int CHAR_F[] = { 4, DIT, DIT, DAH, DIT };
const int CHAR_G[] = { 3, DAH, DAH, DIT };
const int CHAR_H[] = { 4, DIT, DIT, DIT, DIT };
const int CHAR_I[] = { 2, DIT, DIT };
const int CHAR_J[] = { 4, DIT, DAH, DAH, DAH };
const int CHAR_K[] = { 3, DAH, DIT, DAH };
const int CHAR_L[] = { 4, DIT, DAH, DIT, DIT };
const int CHAR_M[] = { 2, DAH, DAH };
const int CHAR_N[] = { 2, DAH, DIT };
const int CHAR_O[] = { 3, DAH, DAH, DAH };
const int CHAR_P[] = { 4, DIT, DAH, DAH, DIT };
const int CHAR_Q[] = { 4, DAH, DAH, DIT, DAH };
const int CHAR_R[] = { 3, DIT, DAH, DIT };
const int CHAR_S[] = { 3, DIT, DIT, DIT };
const int CHAR_T[] = { 1, DAH };
const int CHAR_U[] = { 3, DIT, DIT, DAH };
const int CHAR_V[] = { 4, DIT, DIT, DIT, DAH };
const int CHAR_W[] = { 3, DIT, DAH, DAH };
const int CHAR_X[] = { 4, DAH, DIT, DIT, DAH };
const int CHAR_Y[] = { 4, DAH, DIT, DAH, DAH };
const int CHAR_Z[] = { 4, DAH, DAH, DIT, DIT };
const int CHAR_1[] = { 5, DIT, DAH, DAH, DAH, DAH };
const int CHAR_2[] = { 5, DIT, DIT, DAH, DAH, DAH };
const int CHAR_3[] = { 5, DIT, DIT, DIT, DAH, DAH };
const int CHAR_4[] = { 5, DIT, DIT, DIT, DIT, DAH };
const int CHAR_5[] = { 5, DIT, DIT, DIT, DIT, DIT };
const int CHAR_6[] = { 5, DAH, DIT, DIT, DIT, DIT };
const int CHAR_7[] = { 5, DAH, DAH, DIT, DIT, DIT };
const int CHAR_8[] = { 5, DAH, DAH, DAH, DIT, DIT };
const int CHAR_9[] = { 5, DAH, DAH, DAH, DAH, DIT };
const int CHAR_0[] = { 5, DAH, DAH, DAH, DAH, DAH };
int buttonState = 0; // variable for reading the pushbutton status
void loop(){
}
// Outputs a letter
void outputLetter(int elements[]) {
int count = sizeof(elements) / sizeof(int);
for (int i = 0; i < count; i++) {
digitalWrite(ledPin, HIGH); // turn the LED on
delay(UNIT * elements[i]); // leave it on for the length of the element (either dit or dah)
digitalWrite(ledPin, LOW); // turn the LED off
if (i < count - 1) {
delay(UNIT * ELEMENT_GAP); // pause between elements
}
}
delay(UNIT * LETTER_GAP);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment