Skip to content

Instantly share code, notes, and snippets.

@frogwoo
Last active July 10, 2016 13:10
Show Gist options
  • Save frogwoo/d87d8f4ec28876488e503db394df7c13 to your computer and use it in GitHub Desktop.
Save frogwoo/d87d8f4ec28876488e503db394df7c13 to your computer and use it in GitHub Desktop.
import processing.io.*;
boolean ledStatus = false;
int rectX = 50;
int rectY = 50;
int rectW = 200;
int fillCol;
void setup() {
size(300,300);
GPIO.pinMode(17,GPIO.OUTPUT);
background(255);
stroke(0);
strokeWeight(3);
}
void draw() {
if (ledStatus) {
// if led on, fill rectangle light grey
fillCol = 200;
} else {
// if led off, fill rectangle dark grey
fillCol = 150;
}
fill(fillCol);
// draw the button
rect(rectX,rectY,rectW,rectW);
// turn on/off led
GPIO.digitalWrite(17,ledStatus);
}
void mouseClicked() {
// if mouse pos in button boundary, change led status
if (mouseX > rectX && mouseX < rectX + rectW) {
if (mouseY > rectY && mouseY < rectY + rectW) {
ledStatus = !ledStatus;
}
}
}
void keyPressed() {
// if key pressed, quit program
GPIO.releasePin(17);
exit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment