// Processing code
/*
* Room Status Display
*
* A remote Arduino sends serial data relaying the status of a room
* on campus.
*
* If lights are on and it's loud, room is social.
* If lights are on and it's quiet, room is study.
* If lights are off and it's quiet, room is empty.
* If lights are off and it's loud, room is creepy.
*
* 9/29/15, Robert Zacharias, rz@rzach.me
* released to public domain
* incorporates code from Processing simpleRead serial example.
*/
import processing.serial.*;
Serial myPort;
int val;
PImage hunt; // library floor plan image
color textFill;
String status;
void setup()
{
String portName = Serial.list()[3]; // 4 for Uno on my laptop, 3 for Bluetooth on laptop
myPort = new Serial(this, portName, 9600);
hunt = loadImage("huntmap.png");
rectMode(CORNERS);
textAlign(CENTER);
size(800, 609);
}
void draw()
{
image(hunt, 0, 0);
if ( myPort.available() > 0) {
val = int(myPort.read());
// String inString = myPort.readStringUntil('\n');
// if (inString != null) {
// inString = trim(inString);
// val = int(inString);
// }
print(val);
}
if (val == 4) { // lights and sound = social = blue
fill(0, 0, 255);
textFill = #FFFF00;
status = "social";
} else if (val == 1) { // sound but no lights = creepy = red
fill(255, 0, 0);
textFill = #00FFFF;
status = "creepy";
} else if (val == 2) { // lights but no sound = study = green
fill(0, 255, 0);
textFill = #FF00FF;
status = "study";
} else if (val == 3) { // no lights or sound = empty = black
fill(0);
textFill = 255;
status = "empty";
} else {
status = "";
}
// status rectangle painted over room on map
rect(416, 50, 488, 122);
// room number, larger and stable color
fill(255, 255, 0);
textSize(20);
text("A15", (488+416)/2, (122+53)/2);
// status, smaller and contrasting color
textSize(15);
fill(textFill);
text(status, (488+416)/2, 15+(122+53)/2);
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .