Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Test Code for IO Machine
/*
This is test code for my Input/Output machine.
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 Serial data
char receivedLetter; // as a character
void setup() {
Serial.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);
}
void loop() {
// receive letters through the Serial port
if (Serial.available()) {
char receivedLetter = incomingByte;
receivedLetter = Serial.read();
if (receivedLetter == 'A') {
reset_pins();
set_pins(ROW_W6, COL_W1);
Serial.println ("That's an A!");
Serial.println();
delay(1000);
reset_pins_off();
}
if (receivedLetter == 'B') {
reset_pins();
set_pins(ROW_W6, COL_W2);
Serial.println ("That's a B!");
Serial.println();
delay(1000);
reset_pins_off();
}
if (receivedLetter == 'C') {
reset_pins();
set_pins(ROW_W6, COL_W11);
Serial.println ("That's a C!");
Serial.println();
delay(1000);
reset_pins_off();
}
if (receivedLetter == 'D') {
reset_pins();
set_pins(ROW_W6, COL_W12);
Serial.println ("That's a D!");
Serial.println();
delay(1000);
reset_pins_off();
}
if (receivedLetter == 'E') {
reset_pins();
set_pins(ROW_W6, COL_W13);
Serial.println ("That's an E!");
Serial.println();
delay(1000);
reset_pins_off();
}
if (receivedLetter == 'F') {
reset_pins();
set_pins(ROW_W7, COL_W1);
Serial.println ("That's an F!");
Serial.println();
delay(1000);
reset_pins_off();
}
if (receivedLetter == 'G') {
reset_pins();
set_pins(ROW_W7, COL_W2);
Serial.println ("That's a G!");
Serial.println();
delay(1000);
reset_pins_off();
}
if (receivedLetter == 'H') {
reset_pins();
set_pins(ROW_W7, COL_W11);
Serial.println ("That's an H!");
Serial.println();
delay(1000);
reset_pins_off();
}
if (receivedLetter == 'I') {
reset_pins();
set_pins(ROW_W7, COL_W12);
Serial.println ("That's an I!");
Serial.println();
delay(1000);
reset_pins_off();
}
if (receivedLetter == 'J') {
reset_pins();
set_pins(ROW_W7, COL_W13);
Serial.println ("That's a J!");
Serial.println();
delay(1000);
reset_pins_off();
}
if (receivedLetter == 'K') {
reset_pins();
set_pins(ROW_W4, COL_W1);
Serial.println ("That's a K!");
Serial.println();
delay(1000);
reset_pins_off();
}
if (receivedLetter == 'L') {
reset_pins();
set_pins(ROW_W4, COL_W2);
Serial.println ("That's an L!");
Serial.println();
delay(1000);
reset_pins_off();
}
if (receivedLetter == 'M') {
reset_pins();
set_pins(ROW_W4, COL_W11);
Serial.println ("That's an M!");
Serial.println();
delay(1000);
reset_pins_off();
}
if (receivedLetter == 'N') {
reset_pins();
set_pins(ROW_W4, COL_W12);
Serial.println ("That's an N!");
Serial.println();
delay(1000);
reset_pins_off();
}
if (receivedLetter == 'O') {
reset_pins();
set_pins(ROW_W4, COL_W13);
Serial.println ("That's an O!");
Serial.println();
delay(1000);
reset_pins_off();
}
if (receivedLetter == 'P') {
reset_pins();
set_pins(ROW_W9, COL_W1);
Serial.println ("That's a P!");
Serial.println();
delay(1000);
reset_pins_off();
}
if (receivedLetter == 'Q') {
reset_pins();
set_pins(ROW_W9, COL_W2);
Serial.println ("That's a Q!");
Serial.println();
delay(1000);
reset_pins_off();
}
if (receivedLetter == 'R') {
reset_pins();
set_pins(ROW_W9, COL_W11);
Serial.println ("That's an R!");
Serial.println();
delay(1000);
reset_pins_off();
}
if (receivedLetter == 'S') {
reset_pins();
set_pins(ROW_W9, COL_W12);
Serial.println ("That's an S!");
Serial.println();
delay(1000);
reset_pins_off();
}
if (receivedLetter == 'T') {
reset_pins();
set_pins(ROW_W9, COL_W13);
Serial.println ("That's a T!");
Serial.println();
delay(1000);
reset_pins_off();
}
if (receivedLetter == 'U') {
reset_pins();
set_pins(ROW_W3, COL_W1);
Serial.println ("That's a U!");
Serial.println();
delay(1000);
reset_pins_off();
}
if (receivedLetter == 'V') {
reset_pins();
set_pins(ROW_W3, COL_W2);
Serial.println ("That's a V!");
Serial.println();
delay(1000);
reset_pins_off();
}
if (receivedLetter == 'W') {
reset_pins();
set_pins(ROW_W3, COL_W11);
Serial.println ("That's a W!");
Serial.println();
delay(1000);
reset_pins_off();
}
if (receivedLetter == 'X') {
reset_pins();
set_pins(ROW_W3, COL_W12);
Serial.println ("That's an X!");
Serial.println();
delay(1000);
reset_pins_off();
}
if (receivedLetter == 'Y') {
reset_pins();
set_pins(ROW_W3, COL_W13);
Serial.println ("That's a Y!");
Serial.println();
delay(1000);
reset_pins_off();
}
if (receivedLetter == 'Z') {
reset_pins();
set_pins(ROW_W10, COL_W1);
Serial.println ("That's a Z!");
Serial.println();
delay(1000);
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 back to normal
//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