Skip to content

Instantly share code, notes, and snippets.

@michaelsarduino
Created August 5, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelsarduino/00fa749a0771e82911b6 to your computer and use it in GitHub Desktop.
Save michaelsarduino/00fa749a0771e82911b6 to your computer and use it in GitHub Desktop.
import processing.serial.*;
Serial arduino;
boolean button = false;
int x = 200;
int y = 180;
int b = 100;
int h = 75;
void setup() {
size(500, 500);
arduino = new Serial(this, "COM8", 9600);
}
void draw() {
if(button) {
background(255, 0 ,0);
fill(0);
arduino.write("1");
}
else {
background(0);
arduino.write("0");
fill(255, 0, 0);
}
rect(x, y, b, h);
}
void mousePressed() {
if(mouseX > x && mouseX < x+b && mouseY > y && mouseY < y+h)
{
button = !button;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment