import processing.serial.*; Serial port; char[] inData = new char[20]; // Allocate some space for the string char inChar; // Where to store the character read byte index = 0; // Index into array; where to store the character int val; char[] getData = new char[100]; char KeyData; int charPos=0; String display; void setup() { size(510,500); port = new Serial(this,Serial.list()[5],9600); println(Serial.list()); background(0); } void draw() { if (port.available()>0) { if(index < 19) { inChar = char(port.read()); if (inChar == '#') inData[index] = ' '; else inData[index] = inChar; index++; inData[index] = ' '; } } if (inChar == '#') { // println(str(inData)); printString(); index=0; port.clear(); } } void printString() { fill(100); rect(0,height/2,width,height/2); int x=width/8, y= height -(height/4); for(int j=0; j<20; j++) { fill(255); text(inData[j], x+j*10, y); } } void keyPressed() { int keyIndex = -1; if(key== ' ') { keyIndex=-33; } if (key >= 'A' && key <= 'Z') { keyIndex = key - 'A'; } else if (key >= 'a' && key <= 'z') { keyIndex = key - 'a'; } if (keyIndex == -1) { ToprintString(); clearString(); charPos=0; } else { fill(255); KeyData = char(keyIndex+65); if(keyIndex!=-1) { getData[charPos] = KeyData; charPos++; getData[charPos] = '#'; } } } void ToprintString() { fill(100,50,50); rect(0,0,width,height/2); int x=width/8, y= (height/4); for(int j=0; j<=charPos; j++) { fill(255); if (j!=charPos) text(getData[j], x+j*10, y); print(getData[j]); port.write(getData[j]); } } void clearString() { for (int reset=0; reset<=charPos; reset++) getData[reset] = ':'; }