Sie sind auf Seite 1von 7

// FOOD BLOCK - COMMAND CENTER PROCESSING CODE

import processing.serial.*;

// these are RGB color values for various graphic elements to be


displayed
color bgColor = color (68, 118, 184); // background color of window
color textColor = color (255, 255, 255); // color of the text labels

PFont displayFont; // Global font variable


PFont timeFont;

int msgCount = 0; // total # of messages received

// the data from the latest message received


String nodeName = "--";
int codeNum = 0;
int lastTimer = 0;
int lastCode = 0;
int s;
int m;
int h;

//Last Interaction Variables


String rSecure1 = "--";
String rSecure2 = "--";
String rMoved = "--";
String bDoor = "--";
String bFoodRemoved = "--";
String bUnlocked = "--";
String systemStatus = "--";

//Time Variables
int hour;
String d;
String time;
int newHour;
String hours;
String minutes;

// Interaction Positions
int secure1Position = -8;
int secure2Position = -8;
int remoteMovedPosition = -8;
int doorOpenedPosition = -8;
int foodRemovedPosition = -8;
int unlockedPosition = -8;
int clockMovement;
// Establishes if contact with arduino has been made
boolean firstContact = false;

String val;

// instantiates a serial port object


Serial myPort;

void setup() {

// set up the display window


size(830, 690);
background(bgColor);
noStroke();

// create the font to use for text on screen


displayFont = createFont("Smythe Sans", 18, true);
timeFont = createFont("Smythe Sans Bold", 30, true);
textFont(displayFont);
textAlign(LEFT);

// write the labels (just once, not every time)


fill(textColor);
showLabels();
// make sure we can find the right serial port
println("Here are the available serial ports:");
printArray(Serial.list());

// set to the correct one from the list and open it


myPort = new Serial(this, Serial.list()[1], 9600);

// don't generate a serialEvent() unless you get a newline


character:
myPort.bufferUntil('\n');
}

//Converting computer clock to timestamp


void timeCheck(){
s = second(); // Values from 0 - 59
m = minute(); // Values from 0 - 59
h = hour(); // Values from 0 - 23
}

void timeConversion(){
if (h > 12){
hour = (h - 12);
d = "PM";
}
else if(h == 0){
hour = 12;
d = "AM";
}
else{
hour = h;
d = "AM";
}
if (hour < 10){
hours = "0" + str(hour);
}
else{
hours = str(hour);
}
if (m < 10){
minutes = "0" + str(m);
}
else{
minutes = str(m);
}
time = hours + ":" + minutes + d;
}

// Processing's main loop to refresh the display


void draw() {
//Gets current time and displays it as a string when triggered
timeCheck();
timeConversion();
//Creates Grid for visual interactions
// Displays Messages
showMessages();
interactionColors();
}

// refreshes the display with the list of current messages


void showMessages() {
//Left fill reset
fill(bgColor);
rect(186, 270, 160, 140);
//Right fill reset
fill(bgColor);
rect(680, 270, 160, 140);
//Top fill reset
fill(bgColor);
rect(210, 50, 610, 65);
// show the latest values
fill(textColor);
//Remote Time
textSize(50);
text(systemStatus, 210, 100);
textSize(30);
text(rSecure1, 190, 300);
text(rSecure2, 190, 350);
text(rMoved, 190, 400);
//Food Box Time
text(bDoor, 684, 300);
text(bFoodRemoved, 684, 350);
text(bUnlocked, 684, 400);
}

// write text that doesn't change to the display


void showLabels() {
timeLine();
fill(255, 255, 255);
textFont(displayFont);
textSize(50);
text("Status:", 30, 100);
// Remote
textSize(70);
text("Remote:", 30, 200);
textSize(40);
text("Last Interaction", 30, 250);
textSize(30);
fill(255, 0, 255);
text("Security 1:", 30, 300);
fill(231, 200, 30);
text("Security 2:", 30, 350);
fill(249, 173, 129);
text("Moved:", 78, 400);
// Food Box
textSize(70);
fill(255, 255, 255);
text("Food Box:", 450, 200);
textSize(40);
text("Last Interaction", 450, 250);
textSize(30);
fill(141, 198, 63);
text("Door Opened:", 471, 300);
fill(255, 0, 0);
text("Food Removed:", 450, 350);
fill(0, 174, 239);
text("Unlocked:", 530, 400);
}

void interactionPositions(){
newHour = h*100;
newHour = newHour + m;
clockMovement = (newHour / (25/8)) + 102;
}

void interactionColors(){
// Last Interaction Visual Cues
// Security 1 Disabled
int cubeThickness = 4;
int cubeHeight = 10;
fill(255, 0, 255);
rect(secure1Position, 466, cubeThickness, cubeHeight);
// Security 2 Disabled
fill(231, 200, 30);
rect(secure2Position, 486, cubeThickness, cubeHeight);
// Remote Moved
fill(249, 173, 129);
rect(remoteMovedPosition, 506, cubeThickness, cubeHeight);
// Door Opened
fill(141, 198, 63);
rect(doorOpenedPosition, 526, cubeThickness, cubeHeight);
// Food Removed
fill(255, 0, 0);
rect(foodRemovedPosition, 546, cubeThickness, cubeHeight);
// Unlocked
fill(0, 174, 239);
rect(unlockedPosition, 566, cubeThickness, cubeHeight);
}

void timeLine(){
//Timeline Grid Vertical Lines
int lineThickness = 1;
int gridHeight = 120;
int verticalGridLocation = 460;
fill(100, 100, 100);
rect(30, verticalGridLocation, lineThickness, gridHeight);
rect(94, verticalGridLocation, lineThickness, gridHeight);
rect(184, verticalGridLocation, lineThickness, gridHeight);
rect(274, verticalGridLocation, lineThickness, gridHeight);
rect(364, verticalGridLocation, lineThickness, gridHeight);
rect(454, verticalGridLocation, lineThickness, gridHeight);
rect(544, verticalGridLocation, lineThickness, gridHeight);
rect(634, verticalGridLocation, lineThickness, gridHeight);
rect(724, verticalGridLocation, lineThickness, gridHeight);
rect(788, verticalGridLocation, lineThickness, gridHeight);
//Timeline Grid Horizontal Lines
int lineWidth = 760;
int lineHeight = 1;
int HorizontalGridLocation = 30;
rect(HorizontalGridLocation, 460, lineWidth, lineHeight);
rect(HorizontalGridLocation, 480, lineWidth, lineHeight);
rect(HorizontalGridLocation, 500, lineWidth, lineHeight);
rect(HorizontalGridLocation, 520, lineWidth, lineHeight);
rect(HorizontalGridLocation, 540, lineWidth, lineHeight);
rect(HorizontalGridLocation, 560, lineWidth, lineHeight);
rect(HorizontalGridLocation, 580, lineWidth, lineHeight);

fill(255, 255, 255);


// Time Text
int textHeight = 620;
textSize(20);
text("12AM", 66, textHeight);
text("3AM", 164, textHeight);
text("6AM", 254, textHeight);
text("9AM", 344, textHeight);
text("12PM", 428, textHeight);
text("3PM", 524, textHeight);
text("6PM", 614, textHeight);
text("9PM", 704, textHeight);
}

// this gets called by the serial port when something is ready on it


void serialEvent (Serial myPort) {
// read serial buffer as string
String myString = myPort.readString();
// if we have any other bytes than linefeed
if (myString != null){
// trim crap
myString = trim(myString);
println(myString);
// split the string at commas
// and convert sections into integers.
String sensors[] = split(myString, '\t');
if(sensors.length>1){
if (sensors[0].equals("B") == true){
nodeName = "Food Box";
println(nodeName);
}
else if (sensors[0].equals("R") == true){
nodeName = "Remote";
}
codeNum = int(sensors[1]); //remember to create another value
variable
}
interactionPositions();
switch (codeNum) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
rSecure1 = time;
systemStatus = "1st Layer Unlocked";
secure1Position = clockMovement;
break;
case 6:
rSecure2 = time;
systemStatus = "2nd Layer Unlocked";
secure2Position = clockMovement;
break;
case 7:
rMoved = time;
systemStatus = "Remote Moving";
remoteMovedPosition = clockMovement;
break;
case 8:
bUnlocked = time;
rSecure2 = time;
systemStatus = "System Unlocked";
unlockedPosition = clockMovement;
break;
case 9:
bDoor = time;
systemStatus = "Door Open";
doorOpenedPosition = clockMovement;
break;
case 10:
systemStatus = "System Locked";
break;
case 11:
break;
case 12:
bFoodRemoved = time;
systemStatus = "Alarm";
foodRemovedPosition = clockMovement;
break;
default:
break;
}
}
}

Das könnte Ihnen auch gefallen