import processing.serial.*; Serial myPort; // The serial port int data; // global variables byte[] font = new byte[128]; byte[] mapping = new byte[128]; byte[] addresses = { 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A}; int addr=0; float keyScale; int TX_PAUSE = 150; int OUTPUTXSIZE = 90; int OUTPUTYSIZE = 120; int XSIZE = 15; int YSIZE = 20; int BGGREY= 60; int MARGIN=20; int NUMCHARS = 10; int numChars = 10; int rectWidth; // text buffer to be displayed String typingBuff = ""; // computer generated messages String[] shortMessages = { "hi", "hello", "- -", " - -", "-", "", "welcome", "goodmrning", "how are you" }; int numUtterances = 9; // timing handling for computer generated messages float lastInput = 0; float lastUtterance = 0; float boredTime = 60000; int timeMusingOn = 30000;//int timeMusingOn = 300000; int timeMusingOnScreen = 5000;//int timeMusingOnScreen = 10000; int silentTime = 15000; int j=0; // flags and counts for computer messages boolean stillOn=false; boolean stillOnScreen=false; int numShortMessages = 0; // for initiating deep musings // program state definitions static final int USER_INPUT = 0; static final int ATTENTION_GRABBING = 1; static final int RUMINATION = 2; int state = USER_INPUT; // deep musings String list[] = { "" }; // to hold text file int listPos = 500; boolean longMusings = false; // file handling for recording users input float lastWrote = 0; float saveInterval = 60000; PrintWriter output; PImage[] imgfont = new PImage[128]; int[] CharMap = new int[128]; void setup() { // serial init println(Serial.list()); // I know that the first port in the serial list on my mac // is always my Keyspan adapter, so I open Serial.list()[0]. // Open whatever port is the one you're using. myPort = new Serial(this, Serial.list()[1], 9600); // graphics init size((NUMCHARS*OUTPUTXSIZE)+2*MARGIN, 3*MARGIN+OUTPUTYSIZE+YSIZE); background(BGGREY); loadSSDImages(); // load image thumbnails for text input gui // seven segment font init initCharacterArray(); loadText(); // source text, when speaking with my voice // open output file for recording text inputs output = createWriter("inputs" + "." + day() + "." + hour() + "." + minute() + ".txt"); // jump straight into messages, long musings lastInput = -60000; lastUtterance = -60000; longMusings=true; numShortMessages=5; // welcome message in output window println("Type a letter to send it to the serial device."); }; void putChar(int data, int xpos, int ypos, int xsize, int ysize) { int actualIndex; // prep char data if(mapping[data]!=0) { actualIndex = mapping[data]; } else { actualIndex = data; } // put image to screen image(imgfont[actualIndex], xpos, ypos, xsize, ysize); } void draw() { int charIndex; int i; int nextUtterance; char k; String thisLine; // display current Output buffer to screen for(i=0;iboredTime)&&(millis()-lastUtterance)>silentTime) { println(lastUtterance + "millis"); if(longMusings) { while(list[listPos].length()<=0) { listPos++; if(listPos >= list.length) listPos = 0; } if(j+NUMCHARS < list[listPos].length()) { thisLine = list[listPos].substring(j,j+NUMCHARS); j+=NUMCHARS; } else { thisLine = list[listPos].substring(j, list[listPos].length()); j=0; listPos ++; if(listPos >= list.length) listPos = 0; lastInput=0; } } else { nextUtterance=int(random(numUtterances)); thisLine = shortMessages[nextUtterance]; } typingBuff=""; for(i=0;(i3)longMusings=true; } if(stillOnScreen && ((millis()-lastUtterance)>timeMusingOnScreen)) { background(BGGREY); stillOnScreen=false; }; if(stillOn && (millis()-lastUtterance)>timeMusingOn) { typingBuff=""; sendBuffToDisplay(); stillOn=false; } if(millis() - lastWrote > saveInterval) { // open output file for recording text inputs output.flush(); // Writes the remaining data to the file lastWrote=millis(); //output = createWriter("inputs" + "." + day() + "." + hour() + "." + minute() + ".txt"); }; } void sendBuffToDisplay() { int i; if(random(2)>=1) while(typingBuff.length()boredTime)background(BGGREY); // reset all automatic behavior flags lastInput=millis(); lastUtterance=millis(); longMusings = false; numShortMessages = 0; switch(k){ case 8: if(typingBuff.length()>0){ typingBuff = typingBuff.substring(1); } background(BGGREY); break; case ENTER: // Avoid special keys case RETURN: sendBuffToDisplay(); background(BGGREY); break; case 65535: case 127: case 27: stopProgram(); break; default: //if((k=='M')|| (k=='m') if(typingBuff.length()+ font[39]=0x02; // '=HIGH_RIGHT_VERTICAL //font[39]=0x01; // '=HIGH_BAR //font[46]=0x0C; // .->LOWER_RIGHT_ANGLE font[46]=0x00; //mapping[46]=95; // .->_ font[58]=0x00; //mapping[58]=95; // :->_ font[43]=0x46; // + font[44]=0x00; //mapping[44]=95; // ,->_ font[45]=0x40; // - font[48]=0x3F; // 0 font[49]=0x06; // 1 font[50]=0x5B; // 2 font[51]=0x4F; // 3 font[52]=0x66; // 4 font[53]=0x6D; // 5 font[54]=0x7D; // 6 font[55]=0x07; // 7 font[56]=0x7F; // 8 font[57]=0x67; // 9 for(i=58; i<65; i++) font[i]=0x00; // blank // upper case letters. font[65]=0x77; // A font[66]=0x00; mapping[66] = 98;//font[66]=0x7F; // B font[67]=0x39; // C font[68]=0x00; mapping[68] = 100; // D->d //font[68]=0x3F; // D font[69]=0x79; // E font[70]=0x71; // F font[71]=0x00; mapping[71] = 103; //font[71]=0x3D; // G font[72]=0x76; // H font[73]=0x06; // I font[74]=0x0E; // J font[75]=0x00; mapping[75]=72; // K->H font[76]=0x38; // L font[77]=0x00; mapping[77]=109; // M->m font[78]=0x37; // N font[79]=0x3F; // O font[80]=0x73; // P font[81]=0x00; mapping[81]=113; // Q->q font[82]=0x00; mapping[82]=114; // R->R font[83]=0x6D; // S font[84]=0x07; // T font[85]=0x3E; // U font[86]=0x00; mapping[86]=85; // V->U font[87]=0x00; mapping[87]=119; // W->w font[88]=0x00; mapping[88]=72; // X->H` font[89]=0x66; // Y font[90]=0x5B; // Z for(i=91; i<95; i++) font[i]=0x00; // blank font[95]=0x08; // _ font[96]=0x00; // blank // lower case letters font[97]=0x00; mapping[97]=65;// a->A 5c; // a font[98]=0x7C; // b font[99]=0x58; // c font[100]=0x5E; // d font[101]=0x00; mapping[101]=69; // e->E font[102]=0x71; // f font[103]=0x6F; // g font[104]=0x74; // h font[105]=0x04; // i font[106]=0x0c; // j font[107]=0x00; mapping[107]=72; // k->H font[108]=0x06; // l font[109]=0x2B; // m font[110]=0x54; // n font[111]=0x5C; // o font[112]=0x73; // p font[113]=0x67; // q font[114]=0x50; // r font[115]=0x00; mapping[115]=83; // s->S font[116]=0x46; // t, alternately, could be 0x70 font[117]=0x1C; // u font[118]=0x00; mapping[118]=117; // v->u font[119]=0x6A; // w font[120]=0x00; mapping[120]=72; // x->H font[121]=0x6E; // y font[122]=0x00; mapping[122]=90; // z->Z for(i=123; i<128; i++) font[i]=0x00; // blank } void loadSSDImages() { int i=0; for(i=0; i<45; i++) imgfont[i]=loadImage("blank.JPG"); imgfont[45]=loadImage("blank.JPG"); // imgfont[45]=loadImage("-.JPG"); for(i=46; i<48; i++) imgfont[i]=loadImage("blank.JPG"); imgfont[48]=loadImage("0.JPG"); imgfont[49]=loadImage("1.JPG"); imgfont[50]=loadImage("2.JPG"); imgfont[51]=loadImage("3.JPG"); imgfont[52]=loadImage("4.JPG"); imgfont[53]=loadImage("5.JPG"); imgfont[54]=loadImage("6.JPG"); imgfont[55]=loadImage("7.JPG"); imgfont[56]=loadImage("8.JPG"); imgfont[57]=loadImage("9.JPG"); for(i=58; i<65; i++) imgfont[i]=loadImage("blank.JPG"); // upper case letters. imgfont[65]=loadImage("A.JPG"); imgfont[66]=loadImage("blank.JPG"); imgfont[67]=loadImage("C.JPG"); imgfont[68]=loadImage("blank.JPG"); imgfont[69]=loadImage("E.JPG"); imgfont[70]=loadImage("F.JPG"); imgfont[71]=loadImage("G.JPG"); imgfont[72]=loadImage("H.JPG"); imgfont[73]=loadImage("I.JPG"); imgfont[74]=loadImage("J.JPG"); imgfont[75]=loadImage("blank.JPG"); imgfont[76]=loadImage("L.JPG"); imgfont[77]=loadImage("blank.JPG"); imgfont[78]=loadImage("N.JPG"); imgfont[79]=loadImage("O.JPG"); imgfont[80]=loadImage("P.JPG"); imgfont[81]=loadImage("blank.JPG"); imgfont[82]=loadImage("blank.JPG"); imgfont[83]=loadImage("S.JPG"); imgfont[84]=loadImage("T.JPG"); imgfont[85]=loadImage("U.JPG"); imgfont[86]=loadImage("blank.JPG"); imgfont[87]=loadImage("blank.JPG"); imgfont[88]=loadImage("blank.JPG"); imgfont[89]=loadImage("Y.JPG"); imgfont[90]=loadImage("Z.JPG"); for(i=91; i<95; i++) imgfont[i]=loadImage("blank.JPG"); imgfont[95]=loadImage("blank.JPG"); // imgfont[95]=loadImage("_.JPG"); imgfont[96]=loadImage("blank.JPG"); // lower case letters imgfont[97]=loadImage("blank.JPG"); imgfont[98]=loadImage("_b.JPG"); imgfont[99]=loadImage("_c.JPG"); imgfont[100]=loadImage("_d.JPG"); imgfont[101]=loadImage("blank.JPG"); imgfont[102]=loadImage("_f.JPG"); imgfont[103]=loadImage("_g.JPG"); imgfont[104]=loadImage("_h.JPG"); imgfont[105]=loadImage("_i.JPG"); imgfont[106]=loadImage("_j.JPG"); imgfont[107]=loadImage("blank.JPG"); imgfont[108]=loadImage("_l.JPG"); imgfont[109]=loadImage("blank.JPG"); imgfont[110]=loadImage("_n.JPG"); imgfont[111]=loadImage("_o.JPG"); imgfont[112]=loadImage("_p.JPG"); imgfont[113]=loadImage("_q.JPG"); imgfont[114]=loadImage("_r.JPG"); imgfont[115]=loadImage("blank.JPG"); imgfont[116]=loadImage("_t.JPG"); imgfont[117]=loadImage("_u.JPG"); imgfont[118]=loadImage("blank.JPG"); imgfont[119]=loadImage("blank.JPG"); imgfont[120]=loadImage("blank.JPG"); imgfont[121]=loadImage("_y.JPG"); imgfont[122]=loadImage("blank.JPG"); for(i=123; i<128; i++) imgfont[i]=loadImage("blank.JPG"); } void loadText() { //String lines[] = loadStrings("two stroke engine2.txt"); String lines[] = loadStrings("script.txt"); //String lines[] = loadStrings("SCIP.txt"); //String lines[] = loadStrings("serialart.txt"); println("there are " + lines.length + " lines:"); for (int i=0; i < lines.length; i++) { //println(lines[i]); /*String currLine[] = split(lines[i]); for (int j=0; j < currLine.length; j++) { list=append(list, currLine[j]); //println(currLine[j]); }*/ int j=0; // loop to parse text into NUMCHARS length chunks /*while (j+NUMCHARS < lines[i].length()) { String nextChunk = lines[i].substring(j, j+NUMCHARS); list = append(list, nextChunk); println(nextChunk); j+=NUMCHARS; } // handle remainder of last line list=lines; String nextChunk = lines[i].substring(j, lines[i].length()); list = append(list, nextChunk); println(nextChunk);*/ } list=lines; for(int i=0; i