p14_TweakTheArduinoLogo

はじめに

Processingと連携して、アナログ入力された値でArduinoロゴの背景色を変えます。

プログラム

定義等

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
  Arduino Starter Kit example
  Project 14 - Tweak the Arduino Logo

  This sketch is written to accompany Project 14 in the Arduino Starter Kit

  Parts required:
  - 10 kilohm potentiometer

  Software required:
  - Processing (3.0 or newer) https://processing.org/
  - Active Internet connection

  created 18 Sep 2012
  by Scott Fitzgerald

  https://store.arduino.cc/genuino-starter-kit

  This example code is part of the public domain.
*/
 
 

特に何もしていません。

setup()

23
24
25
26
27
void setup() {
  // initialize serial communication
  Serial.begin(9600);
}
 

Serial.begin()でシリアル通信の初期化を行います。通信速度は9600bpsです。

loop()

28
29
30
31
32
33
void loop() {
  // read the value of A0, divide by 4 and send it as a byte over the
  // serial connection
  Serial.write(analogRead(A0) / 4);
  delay(1);
}

analogRead()で読み取った値を4で割ったものを、Serial.write()でシリアルコンソールに送信します。

delay()で1ミリ秒待ちます。

その他

この例題には、通信相手となるProcessingのプログラムも入っていますが、こちらはよくわからないので掲載していません。

バージョン

Hardware:Arduino Uno
Software:Arduino 1.8.16

最終更新日

September 11, 2021

inserted by FC2 system