Debian Codegraph @

examples/04.Communication/Dimmer/Dimmer.ino

raw
1 /*
2 Dimmer
3
4 Demonstrates sending data from the computer to the Arduino board, in this case
5 to control the brightness of an LED. The data is sent in individual bytes,
6 each of which ranges from 0 to 255. Arduino reads these bytes and uses them to
7 set the brightness of the LED.
8
9 The circuit:
10 - LED attached from digital pin 9 to ground through 220 ohm resistor.
11 - Serial connection to Processing, Max/MSP, or another serial application
12
13 created 2006
14 by David A. Mellis
15 modified 30 Aug 2011
16 by Tom Igoe and Scott Fitzgerald
17
18 This example code is in the public domain.
19
20 https://www.arduino.cc/en/Tutorial/BuiltInExamples/Dimmer
21 */
22
23 const int ledPin = 9; // the pin that the LED is attached to
24
25 void setup() {
26 // initialize the serial communication:
27 Serial.begin(9600);
28 // initialize the ledPin as an output:
29 pinMode(ledPin, OUTPUT);
30 }
31
32 void loop() {
33 byte brightness;
34
35 // check if data has been sent from the computer:
36 if (Serial.available()) {
37 // read the most recent byte (which will be from 0 to 255):
38 brightness = Serial.read();
39 // set the brightness of the LED:
40 analogWrite(ledPin, brightness);
41 }
42 }
43
44 /* Processing code for this example
45
46 // Dimmer - sends bytes over a serial port
47
48 // by David A. Mellis
49 // This example code is in the public domain.
50
51 import processing.serial.*;
52 Serial port;
53
54 void setup() {
55 size(256, 150);
56
57 println("Available serial ports:");
58 // if using Processing 2.1 or later, use Serial.printArray()
59 println(Serial.list());
60
61 // Uses the first port in this list (number 0). Change this to select the port
62 // corresponding to your Arduino board. The last parameter (e.g. 9600) is the
63 // speed of the communication. It has to correspond to the value passed to
64 // Serial.begin() in your Arduino sketch.
65 port = new Serial(this, Serial.list()[0], 9600);
66
67 // If you know the name of the port used by the Arduino board, you can specify
68 // it directly like this.
69 //port = new Serial(this, "COM1", 9600);
70 }
71
72 void draw() {
73 // draw a gradient from black to white
74 for (int i = 0; i < 256; i++) {
75 stroke(i);
76 line(i, 0, i, 150);
77 }
78
79 // write the current X-position of the mouse to the serial port as
80 // a single byte
81 port.write(mouseX);
82 }
83
84 */
85
86 /* Max/MSP v5 patch for this example
87
88 ----------begin_max5_patcher----------
89 1008.3ocuXszaiaCD9r8uhA5rqAeHIa0aAMaAVf1S6hdoYQAsDiL6JQZHQ2M
90 YWr+2KeX4vjnjXKKkKhhiGQ9MeyCNz+X9rnMp63sQvuB+MLa1OlOalSjUvrC
91 ymEUytKuh05TKJWUWyk5nE9eSyuS6jesvHu4F4MxOuUzB6X57sPKWVzBLXiP
92 xZtGj6q2vafaaT0.BzJfjj.p8ZPukazsQvpfcpFs8mXR3plh8BoBxURIOWyK
93 rxspZ0YI.eTCEh5Vqp+wGtFXZMKe6CZc3yWZwTdCmYW.BBkdiby8v0r+ST.W
94 sD9SdUkn8FYspPbqvnBNFtZWiUyLmleJWo0vuKzeuj2vpJLaWA7YiE7wREui
95 FpDFDp1KcbAFcP5sJoVxp4NB5Jq40ougIDxJt1wo3GDZHiNocKhiIExx+owv
96 AdOEAksDs.RRrOoww1Arc.9RvN2J9tamwjkcqknvAE0l+8WnjHqreNet8whK
97 z6mukIK4d+Xknv3jstvJs8EirMMhxsZIusET25jXbX8xczIl5xPVxhPcTGFu
98 xNDu9rXtUCg37g9Q8Yc+EuofIYmg8QdkPCrOnXsaHwYs3rWx9PGsO+pqueG2
99 uNQBqWFh1X7qQG+3.VHcHrfO1nyR2TlqpTM9MDsLKNCQVz6KO.+Sfc5j1Ykj
100 jzkn2jwNDRP7LVb3d9LtoWBAOnvB92Le6yRmZ4UF7YpQhiFi7A5Ka8zXhKdA
101 4r9TRGG7V4COiSbAJKdXrWNhhF0hNUh7uBa4Mba0l7JUK+omjDMwkSn95Izr
102 TOwkdp7W.oPRmNRQsiKeu4j3CkfVgt.NYPEYqMGvvJ48vIlPiyzrIuZskWIS
103 xGJPcmPiWOfLodybH3wjPbMYwlbFIMNHPHFOtLBNaLSa9sGk1TxMzCX5KTa6
104 WIH2ocxSdngM0QPqFRxyPHFsprrhGc9Gy9xoBjz0NWdR2yW9DUa2F85jG2v9
105 FgTO4Q8qiC7fzzQNpmNpsY3BrYPVJBMJQ1uVmoItRhw9NrVGO3NMNzYZ+zS7
106 3WTvTOnUydG5kHMKLqAOjTe7fN2bGSxOZDkMrBrGQ9J1gONBEy0k4gVo8qHc
107 cxmfxVihWz6a3yqY9NazzUYkua9UnynadOtogW.JfsVGRVNEbWF8I+eHtcwJ
108 +wLXqZeSdWLo+FQF6731Tva0BISKTx.cLwmgJsUTTvkg1YsnXmxDge.CDR7x
109 D6YmX6fMznaF7kdczmJXwm.XSOOrdoHhNA7GMiZYLZZR.+4lconMaJP6JOZ8
110 ftCs1YWHZI3o.sIXezX5ihMSuXzZtk3ai1mXRSczoCS32hAydeyXNEu5SHyS
111 xqZqbd3ZLdera1iPqYxOm++v7SUSz
112 -----------end_max5_patcher-----------
113
114 */