//TV
//Adrian Ortega
//Cick the botton and the tv turns on/off
//Class: PUDT 1203 Creative Computing
//Final Project
import processing.serial.*;
Serial arduinoSerial;
boolean arduinoButtonPressed = false;
PImage TVoff;
PImage TVon;
void setup() {
size(500, 500);
background (255,255,255);
arduinoSerial = new Serial(this, Serial.list()[0], 9600);
arduinoSerial.bufferUntil('\n');
TVoff = loadImage("TVoff.png");
TVon = loadImage("TVon.png");
}
void draw() {
if (arduinoButtonPressed) {
image(TVoff, -30, -55);
}
else {
background(220,152,33);
image(TVon, -30, -50);
}
}
void serialEvent(Serial myPort) {
// read a line from the arduino
String inString = arduinoSerial.readStringUntil('\n');
//trim whitespace
inString = trim(inString);
//check value, set flag
if (inString.equals("1")) {
arduinoButtonPressed = true;
}
else {
arduinoButtonPressed = false;
}
}
