@@ -36,55 +36,56 @@ void loop() {
3636
3737// This example code is in the public domain.
3838
39- import processing.serial.*;
40-
41- float redValue = 0; // red value
42- float greenValue = 0; // green value
43- float blueValue = 0; // blue value
44-
45- Serial myPort;
46-
47- void setup() {
48- size(200, 200);
49-
50- // List all the available serial ports
51- // if using Processing 2.1 or later, use Serial.printArray()
52- println(Serial.list());
53-
54- // I know that the first port in the serial list on my mac
55- // is always my Arduino, so I open Serial.list()[0].
56- // Open whatever port is the one you're using.
57- myPort = new Serial(this, Serial.list()[0], 9600);
58- // don't generate a serialEvent() unless you get a newline character:
59- myPort.bufferUntil('\n');
60- }
61-
62- void draw() {
63- // set the background color with the color values:
64- background(redValue, greenValue, blueValue);
65- }
66-
67- void serialEvent(Serial myPort) {
68- // get the ASCII string:
69- String inString = myPort.readStringUntil('\n');
70-
71- if (inString != null) {
72- // trim off any whitespace:
73- inString = trim(inString);
74- // split the string on the commas and convert the
75- // resulting substrings into an integer array:
76- float[] colors = float(split(inString, ","));
77- // if the array has at least three elements, you know
78- // you got the whole thing. Put the numbers in the
79- // color variables:
80- if (colors.length >=3) {
81- // map them to the range 0-255:
82- redValue = map(colors[0], 0, 1023, 0, 255);
83- greenValue = map(colors[1], 0, 1023, 0, 255);
84- blueValue = map(colors[2], 0, 1023, 0, 255);
85- }
86- }
87- }
39+ import processing.serial.*;
40+
41+ float redValue = 0; // red value
42+ float greenValue = 0; // green value
43+ float blueValue = 0; // blue value
44+
45+ Serial myPort;
46+
47+ void setup() {
48+ size(200, 200);
49+
50+ // List all the available serial ports
51+ // if using Processing 2.1 or later, use Serial.printArray()
52+ println(Serial.list());
53+
54+ // I know that the first port in the serial list on my mac
55+ // is always my Arduino, so I open Serial.list()[0].
56+ // Open whatever port is the one you're using.
57+ myPort = new Serial(this, Serial.list()[0], 9600);
58+ // don't generate a serialEvent() unless you get a newline character:
59+ myPort.bufferUntil('\n');
60+ }
61+
62+ void draw() {
63+ // set the background color with the color values:
64+ background(redValue, greenValue, blueValue);
65+ }
66+
67+ void serialEvent(Serial myPort) {
68+ // get the ASCII string:
69+ String inString = myPort.readStringUntil('\n');
70+
71+ if (inString != null) {
72+ // trim off any whitespace:
73+ inString = trim(inString);
74+ // split the string on the commas and convert the
75+ // resulting substrings into an integer array:
76+ float[] colors = float(split(inString, ","));
77+ // if the array has at least three elements, you know
78+ // you got the whole thing. Put the numbers in the
79+ // color variables:
80+ if (colors.length >=3) {
81+ // map them to the range 0-255:
82+ redValue = map(colors[0], 0, 1023, 0, 255);
83+ greenValue = map(colors[1], 0, 1023, 0, 255);
84+ blueValue = map(colors[2], 0, 1023, 0, 255);
85+ }
86+ }
87+ }
88+
8889 */
8990
9091/* Max/MSP patch for this example
0 commit comments