Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
This is my ET Phone Home "Speak and Read" Morse Code DeCoder.
/*
This is my ET Phone Home "Speak and Read" Morse Code DeCoder.
The Arduino code can be adapted for other inputs and outputs.
Other ways that this Input/Output machine can be used are available at www.13wires.com
I chose the Arduino Mega because it has additional serial ports and pins.
*/
// Let's start with identifying the 13 wires.
const int COL_W1 = 48;
const int COL_W2 = 46;
const int ROW_W3 = 44;
const int ROW_W4 = 42;
const int ROW_W5 = 40;
const int ROW_W6 = 38;
const int ROW_W7 = 36;
const int ROW_W8 = 34;
const int ROW_W9 = 32;
const int ROW_W10 = 30;
const int COL_W11 = 28;
const int COL_W12 = 26;
const int COL_W13 = 24;
int incomingByte; // a variable to read incoming Serial2 data
char receivedMorse; // as a character
void setup() {
Serial.begin(9600);
Serial2.begin(9600);
// initialize the LED pins as an outputs:
pinMode(COL_W1, OUTPUT);
pinMode(COL_W2, OUTPUT);
pinMode(COL_W11, OUTPUT);
pinMode(COL_W12, OUTPUT);
pinMode(COL_W13, OUTPUT);
pinMode(ROW_W3, OUTPUT);
pinMode(ROW_W4, OUTPUT);
pinMode(ROW_W5, OUTPUT);
pinMode(ROW_W6, OUTPUT);
pinMode(ROW_W7, OUTPUT);
pinMode(ROW_W8, OUTPUT);
pinMode(ROW_W9, OUTPUT);
pinMode(ROW_W10, OUTPUT);
reset_pins();
set_pins(ROW_W5, COL_W1); //This is like pushing the "OFF" button.
delay(200);
reset_pins_off();
reset_pins();
set_pins(ROW_W8, COL_W13); //This is like pushing the "ON" button.
delay(200);
Serial.println ("ET Phone Home!");
Serial.println();
reset_pins_off();
}
void loop() {
// receive Morse Characters through Serial2
if (Serial2.available()) {
char receivedMorse = incomingByte;
receivedMorse = Serial2.read();
if (incomingByte == ' '); {
Serial2.print ("Do nothing. That's a space.");
}
if (receivedMorse == '1') {
reset_pins();
set_pins(ROW_W8, COL_W11); //Loads Letter Stumper
Serial.println ("That's a #1 ...di-dah-dah-dah-dah!");
Serial.println ("Starting Letter Stumper!");
Serial.println();
delay(200);
reset_pins_off();
}
if (receivedMorse == '2') {
reset_pins();
set_pins(ROW_W8, COL_W1); //Loads Read It
Serial.println ("That's a #2 ...di-di-dah-dah-dah!");
Serial.println ("Starting Read It!");
Serial.println();
delay(200);
reset_pins_off();
}
if (receivedMorse == '3') {
reset_pins();
set_pins(ROW_W5, COL_W13); //Loads Word Maker
Serial.println ("That's a #3 ...di-di-di-dah-dah!");
Serial.println ("Starting Word Maker!");
Serial.println();
delay(200);
reset_pins_off();
}
if (receivedMorse == '4') {
reset_pins();
set_pins(ROW_W8, COL_W12); //Loads Hear It
Serial.println ("That's a #4 ...di-di-di-di-dah!");
Serial.println ("Starting Hear It!");
Serial.println();
delay(200);
reset_pins_off();
}
if (receivedMorse == '5') {
reset_pins();
set_pins(ROW_W5, COL_W2);
Serial.println ("That's a #5 ...di-di-di-di-dit!");
Serial.println ("GO!");
Serial.println();
delay(200);
reset_pins_off();
}
if (receivedMorse == 'A') {
reset_pins();
set_pins(ROW_W6, COL_W1);
Serial.println ("That's an A ...di-dah!");
Serial.println();
delay(200);
reset_pins_off();
}
if (receivedMorse == 'B') {
reset_pins();
set_pins(ROW_W6, COL_W2);
Serial.println ("That's a B ...dah-di-di-dit!");
Serial.println();
delay(200);
reset_pins_off();
}
if (receivedMorse == 'C') {
reset_pins();
set_pins(ROW_W6, COL_W11);
Serial.println ("That's a C ...dah-di-dah-dit!");
Serial.println();
delay(200);
reset_pins_off();
}
if (receivedMorse == 'D') {
reset_pins();
set_pins(ROW_W6, COL_W12);
Serial.println ("That's a D ...dah-di-dit!");
Serial.println();
delay(200);
reset_pins_off();
}
if (receivedMorse == 'E') {
reset_pins();
set_pins(ROW_W6, COL_W13);
Serial.println ("That's an E ...dit!");
Serial.println();
delay(200);
reset_pins_off();
}
if (receivedMorse == 'F') {
reset_pins();
set_pins(ROW_W7, COL_W1);
Serial.println ("That's an F ...di-di-dah-dit!");
Serial.println();
delay(200);
reset_pins_off();
}
if (receivedMorse == 'G') {
reset_pins();
set_pins(ROW_W7, COL_W2);
Serial.println ("That's a G ...dah-dah-dit!");
Serial.println();
delay(200);
reset_pins_off();
}
if (receivedMorse == 'H') {
reset_pins();
set_pins(ROW_W7, COL_W11);
Serial.println ("That's an H ...di-di-di-dit!");
Serial.println();
delay(200);
reset_pins_off();
}
if (receivedMorse == 'I') {
reset_pins();
set_pins(ROW_W7, COL_W12);
Serial.println ("That's an I ...di-dit!");
Serial.println();
delay(200);
reset_pins_off();
}
if (receivedMorse == 'J') {
reset_pins();
set_pins(ROW_W7, COL_W13);
Serial.println ("That's a J ...di-dah-dah-dah!");
Serial.println();
delay(200);
reset_pins_off();
}
if (receivedMorse == 'K') {
reset_pins();
set_pins(ROW_W4, COL_W1);
Serial.println ("That's a K ...dah-di-dah!");
Serial.println();
delay(200);
reset_pins_off();
}
if (receivedMorse == 'L') {
reset_pins();
set_pins(ROW_W4, COL_W2);
Serial.println ("That's an L ...di-dah-di-dit!");
Serial.println();
delay(200);
reset_pins_off();
}
if (receivedMorse == 'M') {
reset_pins();
set_pins(ROW_W4, COL_W11);
Serial.println ("That's an M ...dah-dah!");
Serial.println();
delay(200);
reset_pins_off();
}
if (receivedMorse == 'N') {
reset_pins();
set_pins(ROW_W4, COL_W12);
Serial.println ("That's an N ...dah-dit!");
Serial.println();
delay(200);
reset_pins_off();
}
if (receivedMorse == 'O') {
reset_pins();
set_pins(ROW_W4, COL_W13);
Serial.println ("That's an O ...dah-dah-dah!");
Serial.println();
delay(200);
reset_pins_off();
}
if (receivedMorse == 'P') {
reset_pins();
set_pins(ROW_W9, COL_W1);
Serial.println ("That's a P ...di-dah-dah-dit!");
Serial.println();
delay(200);
reset_pins_off();
}
if (receivedMorse == 'Q') {
reset_pins();
set_pins(ROW_W9, COL_W2);
Serial.println ("That's a Q ...dah-dah-di-dah!");
Serial.println();
delay(200);
reset_pins_off();
}
if (receivedMorse == 'R') {
reset_pins();
set_pins(ROW_W9, COL_W11);
Serial.println ("That's an R ...di-dah-dit!");
Serial.println();
delay(200);
reset_pins_off();
}
if (receivedMorse == 'S') {
reset_pins();
set_pins(ROW_W9, COL_W12);
Serial.println ("That's an S ...di-di-dit!");
Serial.println();
delay(200);
reset_pins_off();
}
if (receivedMorse == 'T') {
reset_pins();
set_pins(ROW_W9, COL_W13);
Serial.println ("That's a T ...dah!");
Serial.println();
delay(200);
reset_pins_off();
}
if (receivedMorse == 'U') {
reset_pins();
set_pins(ROW_W3, COL_W1);
Serial.println ("That's a U ...di-di-dah!");
Serial.println();
delay(200);
reset_pins_off();
}
if (receivedMorse == 'V') {
reset_pins();
set_pins(ROW_W3, COL_W2);
Serial.println ("That's a V ...di-di-di-dah!");
Serial.println();
delay(200);
reset_pins_off();
}
if (receivedMorse == 'W') {
reset_pins();
set_pins(ROW_W3, COL_W11);
Serial.println ("That's a W ...di-dah-dah!");
Serial.println();
delay(200);
reset_pins_off();
}
if (receivedMorse == 'X') {
reset_pins();
set_pins(ROW_W3, COL_W12);
Serial.println ("That's an X ...dah-di-di-dah!");
Serial.println();
delay(200);
reset_pins_off();
}
if (receivedMorse == 'Y') {
reset_pins();
set_pins(ROW_W3, COL_W13);
Serial.println ("That's a Y ...dah-di-dah-dah!");
Serial.println();
delay(200);
reset_pins_off();
}
if (receivedMorse == 'Z') {
reset_pins();
set_pins(ROW_W10, COL_W1);
Serial.println ("That's a Z ...dah-dah-di-dit!");
Serial.println();
delay(200);
reset_pins_off();
}
}
}
void set_pins(int high_pin, int low_pin)
{
// reset all the pins
reset_pins();
// set the high and low pins to output
pinMode(high_pin, OUTPUT);
pinMode(low_pin, OUTPUT);
// set high pin to logic high, low to logic low
digitalWrite(high_pin, HIGH);
digitalWrite(low_pin,LOW);
}
void reset_pins()
{
// start by ensuring all pins are ready to register the character
//COLs are set to HIGH in order to reverse the current, and hence turn them off
digitalWrite(COL_W1, HIGH);
digitalWrite(COL_W2, HIGH);
digitalWrite(COL_W11, HIGH);
digitalWrite(COL_W12, HIGH);
digitalWrite(COL_W13, HIGH);
digitalWrite(ROW_W3, LOW);
digitalWrite(ROW_W4, LOW);
digitalWrite(ROW_W5, LOW);
digitalWrite(ROW_W6, LOW);
digitalWrite(ROW_W7, LOW);
digitalWrite(ROW_W8, LOW);
digitalWrite(ROW_W9, LOW);
digitalWrite(ROW_W10, LOW);
}
void reset_pins_off()
{
//COLUMNS and ROWS all set LOW, just so we don't have a circuit anywhere messing things up
digitalWrite(COL_W1, LOW);
digitalWrite(COL_W2, LOW);
digitalWrite(COL_W11, LOW);
digitalWrite(COL_W12, LOW);
digitalWrite(COL_W13, LOW);
digitalWrite(ROW_W3, LOW);
digitalWrite(ROW_W4, LOW);
digitalWrite(ROW_W5, LOW);
digitalWrite(ROW_W6, LOW);
digitalWrite(ROW_W7, LOW);
digitalWrite(ROW_W8, LOW);
digitalWrite(ROW_W9, LOW);
digitalWrite(ROW_W10, LOW);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment