import processing.serial.*;

Serial myPort;
boolean ledOn = false;

int cx = 200;
int cy = 200;
int radius = 50;

void setup(){
 
  size(400,400);
  println(Serial.list());
  myPort = new Serial(this,Serial.list()[3],9600);
  
}

void draw(){
  background(0,0,0);
  
  if(ledOn){
     fill(0,200,100); 
  }else{
    fill(200);
  }
  ellipse(cx,cy,radius * 2,radius * 2);
  fill(0);
  textAlign(CENTER,CENTER);
  text(ledOn ? "ON" : "OFF", cx,cy);

}


void mousePressed(){
 // マウスがボタンないにあるか確認
 float d = dist(mouseX,mouseY,cx,cy);
 if (d < radius){
    ledOn = !ledOn;
    myPort.write(ledOn? '1' : '0');
 }
  
}
