LoginSignup
0
1

More than 1 year has passed since last update.

Processing で、Arduino の LED を点灯させる

Last updated at Posted at 2017-07-31

Arduino IDEと、Processingがインストールされている状態からの設定の方法は、こちら。

マウスを押さえている間は、Arduino についている LED がつき、マウスを放せば、LED が消えるサンプルです。

button/button.pde
// --------------------------------------------------------------
/*
    button.pde

                    Jul/31/2017

*/
// --------------------------------------------------------------
import processing.serial.*;
import cc.arduino.*;

Arduino arduino;
int ledPin = 13;
color bgColor = color(0);

void setup() {
size(400, 200);
arduino = new Arduino(this, Arduino.list()[0], 57600);
arduino.pinMode(ledPin, Arduino.OUTPUT);
}

void draw() {
background(bgColor);
}

void mousePressed() {
arduino.digitalWrite(ledPin, Arduino.HIGH);
bgColor = color(0,255,0);
}

void mouseReleased() {
arduino.digitalWrite(ledPin, Arduino.LOW);
bgColor = color(0);
}

// --------------------------------------------------------------

ProcessingIDE の中からだけでなく、コンソールからも実行ができます。

processing-java  --sketch=button --run
0
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1