-
Notifications
You must be signed in to change notification settings - Fork 0
/
example
42 lines (30 loc) · 1.1 KB
/
example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
To use:
* Using the Arduino software, upload the StandardFirmata example (located
in Examples > Firmata > StandardFirmata) to your Arduino board.
For more information, see: http://playground.arduino.cc/Interfacing/Processing
*/
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
void setup() {
size(470, 280);
// Prints out the available serial ports.
println(Arduino.list());
// Modify this line, by changing the "0" to the index of the serial
// port corresponding to your Arduino board (as it appears in the list
// printed by the line above).
arduino = new Arduino(this, Arduino.list()[0], 57600);
// Alternatively, use the name of the serial port corresponding to your
// Arduino (in double-quotes), as in the following line.
//arduino = new Arduino(this, "/dev/tty.usbmodem621", 57600);
// Set the Arduino digital pins as inputs.
arduino.pinMode(0, Arduino.INPUT);
}
void draw() {
int potVal = arduino.analogRead(0);
float colorVal = map(potVal, 0, 1023, 0, 255);
println(colorVal);
fill(colorVal, 127, 127);
rect(0, 0, width, height);
}