In general, this is a fairly simple task; however, because I wanted to have the computer GUI that talked to the Arduino it made the difficulty level a little harder.
For the first part, I just used an actual keyboard up, down, left, right arrows and enter to control the Processing GUI. I will then convert the keyboard input to serial input from the Arduino but it should look very similar. Here is the initial Processing Code:
//Variables
static final int enterh = 30;
PFont f;
int i, charSelect, col;
color fillUP, fillDOWN, fillLEFT, fillRIGHT, fillENTER;
String words;
String[] keyboard = {"a", "b", "c", "d", "e",
"f", "g", "h", "i", "j", "k",
"l", "m", "n", "o", "p", "q",
"r", "s", "t", "u", "v", "w",
"x", "y", "z", "space"};
//Setup Loop
void setup() {
size(400, 360);
words = "";
charSelect = 0;
col = 0;
background(1);
// Create the font
f = createFont("Ethnocentric", 20);
i=0;
background(0);
}
//Draw loop
void draw() {
background(0);
textAlign(LEFT);
textFont(f,9);
fill(255);
text("a b c d e f g h i j k l m", width/2-4*enterh, height/4);
text("n o p q r s t u v w x y z", width/2-4*enterh, height/4+16);
text("space", width/2-4*enterh, height/4+32);
textFont(f, 30);
strokeWeight(1);
stroke(255, 255, 255);
rectMode(CENTER);
fill(0);
//rect(width/2,40, 90, 40);
rectMode(CORNER);
fill(255, 0, 0);
textAlign(CENTER);
text(keyboard[charSelect], width/2, 50);
strokeWeight(4);
stroke(15, 242, 39);
fill(0);
rect(width/2-4*enterh, height/2-1.5*enterh,enterh*8, enterh*4);
stroke(237, 255, 3);
fill(fillENTER);
rect((width/2)-enterh, height/2, enterh*2, enterh);
fill(fillLEFT);
triangle((width/2)-enterh*1.66, height*.5, (width/2)-enterh*1.66, height*.5+enterh,(width/2)-(enterh*2.5), height*.5+(enterh/2));
fill(fillRIGHT);
triangle((width/2)+enterh*1.66, height*.5, (width/2)+enterh*1.66, height*.5+enterh,(width/2)+(enterh*2.5), height*.5+(enterh/2));
fill(fillUP);
triangle((width/2)-enterh, height*.5-enterh*.333, (width/2)+enterh, height*.5-enterh*.33,(width/2), height*.5-enterh);
fill(fillDOWN);
triangle((width/2)-enterh, height*.5+enterh*1.333, (width/2)+enterh, height*.5+enterh*1.33,(width/2), height*.5+enterh*2);
delay(200);
fillUP = color(0, 0, 0);
fillDOWN = color(0, 0, 0);
fillLEFT = color(0, 0, 0);
fillRIGHT = color(0, 0, 0);
fillENTER = color(0, 0, 0);
textAlign(CENTER);
textFont(f, 16);
fill(237, 255, 3);
text(words, width/2, height*.9);
//println(words);
}
void keyPressed() {
if (key == CODED)
{
if (keyCode == UP)
{
fillUP = color(255, 0, 0);
if(col>0)
col -= 1;
else
col = 2;
if(col == 2)
charSelect = 26;
else{
charSelect -= 13;
}
}
else if (keyCode == DOWN)
{
fillDOWN = color(255, 0, 0);
if(col <2)
col += 1;
else
col = 0;
if(col == 2)
charSelect = 26;
else if(col == 0)
charSelect = 0;
else
charSelect += 13;
}
else if(keyCode == LEFT)
{
fillLEFT= color(255, 0, 0);
if(charSelect>0)
charSelect--;
else
charSelect = keyboard.length-1;
}
else if(keyCode == RIGHT)
{
fillRIGHT= color(255, 0, 0);
if(charSelect<keyboard.length-1)
charSelect++;
else
charSelect = 0;
}
}
else if(key == ENTER)
{
fillENTER = color(255, 0, 0);
if(keyboard[charSelect] == "space")
words = words + " ";
else
words = words + keyboard[charSelect];
}
else
{
fillUP = color(0, 0, 0);
fillDOWN = color(0, 0, 0);
fillLEFT = color(0, 0, 0);
fillRIGHT = color(0, 0, 0);
fillENTER = color(0, 0, 0);
}
if(charSelect < 13)
col = 0;
else if(charSelect <26)
col = 1;
else
col = 2;
println(col + " " + charSelect);
}
No comments:
Post a Comment