The Code

I have decided not to put this up on Instructables because there are already a few projects like this one out there. This project was really just more of a test to see if I could do it, not to actually have other people build it. I will keep this blog updated and if anyone asks for the .stl files to print their own I will gladly give it to them.

I have cleaned up the code enough to the point where I feel it is suitable for me to share it. The Arduino code was written on 1.0.4 and the Processing was done on 32 bit 2.0b9, for some reason the 64 bit wouldn’t read the serial port. Click more for the code. 

ARDUINO

const int buttonPin1 = A5;
const int buttonPin2 = A0;
const int buttonPin3 = A4;
const int buttonPin4 = A2;

int a = 0;
int b = 0;
int c = 0;
int d = 0;

int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;

int prevb = 0;

void setup() {
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(buttonPin4, INPUT);
Serial.begin(9600);

}

int readButtons1(int pin) // LEFT HAND
{
int a1,a2 = 0;
a2=analogRead(pin);
{
a1=0;
}
if (a2<270 && a2>240)
{
a1=4; // button 2 pressed
}
else
if (a2>310 && a2<360)
{
a1=8; // button 3 pressed
}
else
if (a2>500 && a2<520)
{
a1=16; // button 4 pressed
}
else
if (a2>1000)
{
a1=32; // button 5 pressed
}
return a1;
}

int readButtons2(int pin) // RIGHT HAND
{
int b1,b2 = 0;
b2=analogRead(pin);
{
b1=0;
}
if (b2>120 && b2<145)
{
b1=64; // button 1 pressed
}
else
if (b2<180 && b2>150)
{
b1=128; // button 2 pressed
}
else
if (b2>210 && b2<240)
{
b1=256; // button 3 pressed
}
else
if (b2>310 && b2<350)
{
b1=512; // button 4 pressed
}
else
if (b2>600)
{
b1=1024; // button 5 pressed
}
return b1;
}

int readButtons3(int pin) // LEFT THUMB
{
int c1,c2 = 0;
c2=analogRead(pin);
{
c1=0;
}
if (c2>1000)
{
c1=2;
}

return c1;
}

int readButtons4(int pin) // TOGGLE SWITCH
{
int d1,d2 = 0;
d2=analogRead(pin);
{
d1=0;
}
if (d2>1000)
{
d1=1;
}

return d1;
}

void loop(){
a=readButtons1(5);
b=readButtons2(0);
c=readButtons3(4);
d=readButtons4(2);

if (b != prevb){
Serial.println(a+b+c+d);
}
delay(50);
prevb = b;
}

 

 

PROCESSING

import processing.serial.*;
Serial port;
float val = 0;
float preval = 0;
PrintWriter output;

void setup()
{
port = new Serial(this, “COM4”, 9600);
port.bufferUntil(‘\n’);
output = createWriter(“text.txt”);
}

void draw()
{
if (val == 66 && val != preval)
{
print(” “);
output.print(” “);
}
if (val == 68 && val != preval)
{
print(“o”);
output.print(“o”);
}
if (val == 72 && val != preval)
{
print(“i”);
output.print(“i”);
}
if (val == 80 && val != preval)
{
print(“n”);
output.print(“n”);
}
if (val == 96 && val != preval)
{
print(“s”);
output.print(“s”);
}
if (val == 130 && val != preval)
{
print(“l”);
output.print(“l”);
}
if (val == 132 && val != preval)
{
print(“e”);
output.print(“e”);
}
if (val == 136 && val != preval)
{
print(“r”);
output.print(“r”);
}
if (val == 144 && val != preval)
{
print(“y”);
output.print(“y”);
}
if (val == 160 && val != preval)
{
print(“p”);
output.print(“p”);
}
if (val == 258 && val != preval)
{
print(“c”);
output.print(“c”);
}
if (val == 260 && val != preval)
{
print(“d”);
output.print(“d”);
}
if (val == 264 && val != preval)
{
print(“t”);
output.print(“t”);
}
if (val == 272 && val != preval)
{
print(“g”);
output.print(“g”);
}
if (val == 288 && val != preval)
{
print(“v”);
output.print(“v”);
}
if (val == 514 && val != preval)
{
print(“u”);
output.print(“u”);
}
if (val == 516 && val != preval)
{
print(“w”);
output.print(“w”);
}
if (val == 520 && val != preval)
{
print(“f”);
output.print(“f”);
}
if (val == 528 && val != preval)
{
print(“a”);
output.print(“a”);
}
if (val == 544 && val != preval)
{
print(“k”);
output.print(“k”);
}
if (val == 1026 && val != preval)
{
print(“m”);
output.print(“m”);
}
if (val == 1028 && val != preval)
{
print(“x”);
output.print(“x”);
}
if (val == 1032 && val != preval)
{
print(“j”);
output.print(“j”);
}
if (val == 1040 && val != preval)
{
print(“b”);
output.print(“b”);
}
if (val == 1056 && val != preval)
{
print(“h”);
output.print(“h”);
}

if (val == 70 && val != preval)
{
print(“q”);
output.print(“q”);
}
if (val == 74 && val != preval)
{
print(“z”);
output.print(“z”);
}
if (val == 82 && val != preval)
{
print(“0”);
output.print(“0”);
}
if (val == 98 && val != preval)
{
print(“/”);
output.print(“/”);
}
if (val == 134 && val != preval)
{
print(“1”);
output.print(“1”);
}
if (val == 138 && val != preval)
{
print(“4”);
output.print(“4”);
}
if (val == 146 && val != preval)
{
print(“7”);
output.print(“7”);
}
if (val == 162 && val != preval)
{
print(“(“);
output.print(“(“);
}
if (val == 262 && val != preval)
{
print(“2”);
output.print(“2”);
}
if (val == 266 && val != preval)
{
print(“5”);
output.print(“5”);
}
if (val == 274 && val != preval)
{
print(“8”);
output.print(“8”);
}
if (val == 290 && val != preval)
{
print(“)”);
output.print(“)”);
}
if (val == 518 && val != preval)
{
print(“3”);
output.print(“3”);
}
if (val == 522 && val != preval)
{
print(“6”);
output.print(“6”);
}
if (val == 530 && val != preval)
{
print(“9”);
output.print(“9”);
}
if (val == 546 && val != preval)
{
print(“?”);
output.print(“?”);
}
if (val == 1030 && val != preval)
{
print(“.”);
output.print(“.”);
}
if (val == 1034 && val != preval)
{
print(“,”);
output.print(“,”);
}
if (val == 1042 && val != preval)
{
print(“!”);
output.print(“!”);
}
if (val == 1058 && val != preval)
{
print(“‘”);
output.print(“‘”);
}

{
if (val == 67 && val != preval)
{
print(” “);
output.print(” “);
}
if (val == 69 && val != preval)
{
print(“O”);
output.print(“O”);
}
if (val == 73 && val != preval)
{
print(“I”);
output.print(“I”);
}
if (val == 81 && val != preval)
{
print(“N”);
output.print(“N”);
}
if (val == 97 && val != preval)
{
print(“S”);
output.print(“S”);
}
if (val == 131 && val != preval)
{
print(“L”);
output.print(“L”);
}
if (val == 133 && val != preval)
{
print(“E”);
output.print(“E”);
}
if (val == 137 && val != preval)
{
print(“R”);
output.print(“R”);
}
if (val == 145 && val != preval)
{
print(“Y”);
output.print(“Y”);
}
if (val == 161 && val != preval)
{
print(“P”);
output.print(“P”);
}
if (val == 259 && val != preval)
{
print(“C”);
output.print(“C”);
}
if (val == 261 && val != preval)
{
print(“D”);
output.print(“D”);
}
if (val == 265 && val != preval)
{
print(“T”);
output.print(“T”);
}
if (val == 273 && val != preval)
{
print(“G”);
output.print(“G”);
}
if (val == 289 && val != preval)
{
print(“V”);
output.print(“V”);
}
if (val == 515 && val != preval)
{
print(“U”);
output.print(“U”);
}
if (val == 517 && val != preval)
{
print(“W”);
output.print(“W”);
}
if (val == 521 && val != preval)
{
print(“F”);
output.print(“F”);
}
if (val == 529 && val != preval)
{
print(“A”);
output.print(“A”);
}
if (val == 545 && val != preval)
{
print(“K”);
output.print(“K”);
}
if (val == 1027 && val != preval)
{
print(“M”);
output.print(“M”);
}
if (val == 1029 && val != preval)
{
print(“X”);
output.print(“X”);
}
if (val == 1033 && val != preval)
{
print(“J”);
output.print(“J”);
}
if (val == 1041 && val != preval)
{
print(“B”);
output.print(“B”);
}
if (val == 1057 && val != preval)
{
print(“H”);
output.print(“H”);
}

if (val == 71 && val != preval)
{
print(“Q”);
output.print(“Q”);
}
if (val == 75 && val != preval)
{
print(“Z”);
output.print(“Z”);
}
if (val == 83 && val != preval)
{
print(“0”);
output.print(“0”);
}
if (val == 99 && val != preval)
{
print(“*”);
output.print(“*”);
}
if (val == 135 && val != preval)
{
print(“1”);
output.print(“1”);
}
if (val == 139 && val != preval)
{
print(“4”);
output.print(“4”);
}
if (val == 147 && val != preval)
{
print(“7”);
output.print(“7”);
}
if (val == 163 && val != preval)
{
print(“(“);
output.print(“<“);
}
if (val == 263 && val != preval)
{
print(“2”);
output.print(“2”);
}
if (val == 267 && val != preval)
{
print(“5”);
output.print(“5”);
}
if (val == 275 && val != preval)
{
print(“8”);
output.print(“8”);
}
if (val == 291 && val != preval)
{
print(“)”);
output.print(“>”);
}
if (val == 519 && val != preval)
{
print(“3”);
output.print(“3”);
}
if (val == 523 && val != preval)
{
print(“6”);
output.print(“6”);
}
if (val == 531 && val != preval)
{
print(“9”);
output.print(“9”);
}
if (val == 547 && val != preval)
{
print(“@”);
output.print(“@”);
}
if (val == 1031 && val != preval)
{
print(“&”);
output.print(“&”);
}
if (val == 1035 && val != preval)
{
print(“%”);
output.print(“%”);
}
if (val == 1043 && val != preval)
{
print(“$”);
output.print(“$”);
}
if (val == 1059 && val != preval)
{
print(“#”);
output.print(“#”);
}
preval = val;
}

void keyPressed() {
output.flush(); // Writes the remaining data to the file
output.close(); // Finishes the file
exit(); // Stops the program
}

void serialEvent(Serial port)
{
val = float(port.readStringUntil(‘\n’));
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: