top of page

Processing

□ ワークショップ

001 マウスのボタンを押したり離したりすることで、外部に接続したLEDが点灯したり消灯したりするプログラム

Arduino :

#define LED 13

void setup()
{
    Serial.begin(9600);      // 通信速度:9600bps
    pinMode(LED, OUTPUT);
}

void loop()
{
    char c, v;
    if(Serial.available() > 0){      // 1つ以上のデータを受信したならば
        c = Serial.read();            // 1つ目のデータを読み込む
        if(c == 'a'){                    // 「a」を受信したら
            digitalWrite(LED, HIGH);
        } else if (c == 'b') {
          digitalWrite(LED, LOW);
        }
    }
}

Processing:

import processing.serial.*;    // Arduinoと通信するためのライブラリの読込み

Serial port;                   // シリアル通信を行うための変数の定義

void setup() {
    size(255, 255);
    port = new Serial(this, "COM7", 9600);
    rectMode(CENTER);
    rect(127, 127,120, 120);
}

void draw() {
    if (mousePressed == true ) {
      port.write('a');
      fill(255, 0, 0);
      ellipse(127, 127, 80, 80);
    } else {
      port.write('b') ;
      fill(255, 255, 0);
      ellipse(127, 127, 80, 80);
    }
}

  • facebook
  • twitter
  • linkedin

©2019 by Healing-Zoo. Proudly created with Wix.com

bottom of page