source: arduino-1-6-7/trunk/fuentes/arduino-ide-amd64/examples/04.Communication/VirtualColorMixer/VirtualColorMixer.ino @ 46

Last change on this file since 46 was 46, checked in by jrpelegrina, 4 years ago

First release to Xenial

File size: 4.6 KB
Line 
1/*
2  This example reads three analog sensors (potentiometers are easiest)
3 and sends their values serially. The Processing and Max/MSP programs at the bottom
4 take those three values and use them to change the background color of the screen.
5
6 The circuit:
7 * potentiometers attached to analog inputs 0, 1, and 2
8
9 http://www.arduino.cc/en/Tutorial/VirtualColorMixer
10
11 created 2 Dec 2006
12 by David A. Mellis
13 modified 30 Aug 2011
14 by Tom Igoe and Scott Fitzgerald
15
16  This example code is in the public domain.
17 */
18
19const int redPin = A0;          // sensor to control red color
20const int greenPin = A1;        // sensor to control green color
21const int bluePin = A2;         // sensor to control blue color
22
23void setup() {
24  Serial.begin(9600);
25}
26
27void loop() {
28  Serial.print(analogRead(redPin));
29  Serial.print(",");
30  Serial.print(analogRead(greenPin));
31  Serial.print(",");
32  Serial.println(analogRead(bluePin));
33}
34
35/* Processing code for this example
36
37//  This example code is in the public domain.
38
39import processing.serial.*;
40
41float redValue = 0;        // red value
42float greenValue = 0;      // green value
43float blueValue = 0;       // blue value
44
45Serial myPort;
46
47void 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
62void draw() {
63  // set the background color with the color values:
64  background(redValue, greenValue, blueValue);
65}
66
67void 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
89 */
90
91/* Max/MSP patch for this example
92
93 ----------begin_max5_patcher----------
941512.3oc4Z00aaaCE8YmeED9ktB35xOjrj1aAsXX4g8xZQeYoXfVh1gqRjdT
95TsIsn+2K+PJUovVVJ1VMdCAvxThV7bO7b48dIyWtXxzkxaYkSA+J3u.Sl7kK
96lLwcK6MlT2dxzB5so4zRW2lJXeRt7elNy+HM6Vs61uDDzbOYkNmo02sg4euS
974BSede8S2P0o2vEq+aEKU66PPP7b3LPHDauPvyCmAvv4v6+M7L2XXF2WfCaF
98lURgVPKbCxzKUbZdySDUEbgABN.ia08R9mccGYGn66qGutNir27qWbg8iY+7
99HDRx.Hjf+OPHCQgPdpQHoxhBlwB+QF4cbkthlCRk4REnfeKScs3ZwaugWBbj
100.PS+.qDPAkZkgPlY5oPS4By2A5aTLFv9pounjsgpnZVF3x27pqtBrRpJnZaa
101C3WxTkfUJYA.BzR.BhIy.ehquw7dSoJCsrlATLckR.nhLPNWvVwL+Vp1LHL.
102SjMG.tRaG7OxT5R2c8Hx9B8.wLCxVaGI6qnpj45Ug84kL+6YIM8CqUxJyycF
1037bqsBRULGvwfWyRMyovElat7NvqoejaLm4f+fkmyKuVTHy3q3ldhB.WtQY6Z
104x0BSOeSpTqA+FW+Yy3SyybH3sFy8p0RVCmaMpTyX6HdDZ2JsPbfSogbBMueH
105JLd6RMBdfRMzPjZvimuWIK2XgFA.ZmtfKoh0Sm88qc6OF4bDQ3P6kEtF6xej
106.OkjD4H5OllyS+.3FlhY0so4xRlWqyrXErQpt+2rsnXgQNZHZgmMVzEofW7T
107S4zORQtgIdDbRHrObRzSMNofUVZVcbKbhQZrSOo934TqRHIN2ncr7BF8TKR1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oMZssNTzRNEnE6gYPXazZaMF921syaLWyAeBXvCESA8
126ASi6Zyw8.RQi65J8ZsNx3ho93OhGWENtWpowepae4YhCFeLErOLENtXJrOSc
127iadi39rf4hwc8xdhHz3gn3dBI7iDRlFe8huAfIZhq
128-----------end_max5_patcher-----------
129
130
131 */
Note: See TracBrowser for help on using the repository browser.