0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Processing】で【Arduino】を動かす

Posted at

概要

Arduinoを用いてLチカ,サーボモータの制御についてメモ程度に記載します。

実践

Lチカ

LEDを0.5[s]間隔で点滅します。

led.pde
import processing.serial.*;
import cc.arduino.*;
import org.firmata.*;

Arduino arduino;

int pin = 13; //pin番号

void setup()
{
  size(100,100);

  arduino = new Arduino(this, Arduino.list()[0], 57600);

  arduino.pinMode(pin, Arduino.OUTPUT);
}

void draw()
{
  arduino.digitalWrite(pin,Arduino.HIGH);
  delay(500);
  arduino.digitalWrite(pin,Arduino.LOW);
  delay(500);
}

サーボモータ

サーボモータが0~180°を行った来たします。

servomoter.pde
import processing.serial.*;
import cc.arduino.*;
import org.firmata.*;

Arduino arduino;

int pin = 13; //pin番号

void setup()
{
  size(100,100);

  arduino = new Arduino(this, Arduino.list()[0], 57600);

  arduino.pinMode(pin, Arduino.SERVO);
}

void draw()
{
  arduino.servoWrite(pin, 90);
  delay(1000);
  arduino.servoWrite(pin, 0);
  delay(1000);
  arduino.servoWrite(pin, 90);
  delay(1000);
  arduino.servoWrite(pin, 180);
  delay(1000);
}
0
1
0

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?