char val; int ledpin = 8; void setup() { pinMode(ledpin, OUTPUT); Serial.begin(9600); } void loop() { if( Serial.available() ) { val = Serial.read(); } if( val == 'H' ) { digitalWrite(ledpin, HIGH); } else { digitalWrite(ledpin, LOW); } delay(100); } import processing.serial.*; Serial port; color currentcolor; RectButton rect1, rect2; boolean locked = false; void setup() { size(200, 200); color baseColor = color(102, 102, 102); currentcolor = baseColor; println(Serial.list()); port = new Serial(this, Serial.list()[2], 9600); int x = 30; int y = 100; int size = 50; color buttoncolor = color(153, 102, 102); color highlight = color(102, 51, 51); rect1 = new RectButton(x, y, size, buttoncolor, highlight); x = 90; y = 100; size = 50; buttoncolor = color(153, 153, 153); highlight = color(102, 102, 102); rect2 = new RectButton(x, y, size, buttoncolor, highlight); } void draw() { background(currentcolor); stroke(255); update(mouseX, mouseY); rect1.display(); rect2.display(); } void update(int x, int y) { if(locked == false) { rect1.update(); rect2.update(); } else { locked = false; } if(mousePressed) { if(rect1.pressed()) { currentcolor = rect1.basecolor; port.write('H'); } else if(rect2.pressed()) { currentcolor = rect2.basecolor; port.write('L'); } } } class Button { int x, y; int size; color basecolor, highlightcolor; color currentcolor; boolean over = false; boolean pressed = false; void update() { if(over()) { currentcolor = highlightcolor; } else { currentcolor = basecolor; } } boolean pressed() { if(over) { locked = true; return true; } else { locked = false; return false; } } boolean over() { return true; } void display() { } } class RectButton extends Button { RectButton(int ix, int iy, int isize, color icolor, color ihighlight) { x = ix; y = iy; size = isize; basecolor = icolor; highlightcolor = ihighlight; currentcolor = basecolor; } boolean over() { if( overRect(x, y, size, size) ) { over = true; return true; } else { over = false; return false; } } void display() { stroke(255); fill(currentcolor); rect(x, y, size, size); } } boolean overRect(int x, int y, int width, int height) { if (mouseX >= x && mouseX <= x+width && mouseY >= y && mouseY <= y+height) { return true; } else { return false; } }