/** * Simple Read from Serial Modified with Color Changing Words * * Read data from the serial port and change the color of variable * text according to serial readout */ import processing.serial.*; Serial myPort; // Create object from Serial class int val; // Data received from the serial port PFont fontA; void setup() { size(400, 400); String portName = Serial.list()[0]; print("Port " + portName + "\n"); myPort = new Serial(this, portName, 9600); fontA = loadFont("BellGothicStd-Black-48.vlw"); textFont(fontA, 48); } void draw() { if ( myPort.available() > 0) { // If data is available, val = myPort.read(); // read it and store it in val } print("Val " + val + "\n"); background(val-50); // Set background to grey if (val == 0) { // If the serial value is 0, fill(0,0,255); // set fill to blue text("brrr!",159,300); } if ((val)>0 && (val)<63) { //If serial value is greater than 0, less than 63, fill(0,0,val+100); //set fill to shades of blue text("cold",159,260); //read text "cold" } if ((val)>62 && (val)<128) { fill(0,0,val+100); //set fill to shades of blue text("cool",159,220); //read text "cool" } if ((val)>127 && (val)<190) { fill(val,0,0); //set fill to shades of red text("warm",159,180); //read text "warm" } if ((val)>189 && (val)<256) { fill (val,0,0); //set fill to shades of red text("hot",159,140); //read text "hot" } }