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

Last change on this file since 4837 was 4837, checked in by daduve, 2 years ago

Adding new version

File size: 3.6 KB
Line 
1/*
2  Dimmer
3
4 Demonstrates the sending data from the computer to the Arduino board,
5 in this case to control the brightness of an LED.  The data is sent
6 in individual bytes, each of which ranges from 0 to 255.  Arduino
7 reads these bytes and uses them to set the brightness of the LED.
8
9 The circuit:
10 LED attached from digital pin 9 to ground.
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 http://www.arduino.cc/en/Tutorial/Dimmer
21
22 */
23
24const int ledPin = 9;      // the pin that the LED is attached to
25
26void setup() {
27  // initialize the serial communication:
28  Serial.begin(9600);
29  // initialize the ledPin as an output:
30  pinMode(ledPin, OUTPUT);
31}
32
33void loop() {
34  byte brightness;
35
36  // check if data has been sent from the computer:
37  if (Serial.available()) {
38    // read the most recent byte (which will be from 0 to 255):
39    brightness = Serial.read();
40    // set the brightness of the LED:
41    analogWrite(ledPin, brightness);
42  }
43}
44
45/* Processing code for this example
46 // Dimmer - sends bytes over a serial port
47 // by David A. Mellis
48 //This example code is in the public domain.
49
50 import processing.serial.*;
51 Serial port;
52
53 void setup() {
54 size(256, 150);
55
56 println("Available serial ports:");
57 // if using Processing 2.1 or later, use Serial.printArray()
58 println(Serial.list());
59
60 // Uses the first port in this list (number 0).  Change this to
61 // select the port corresponding to your Arduino board.  The last
62 // parameter (e.g. 9600) is the speed of the communication.  It
63 // has to correspond to the value passed to Serial.begin() in your
64 // 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
68 // can specify 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/* Max/MSP v5 patch for this example
86
87----------begin_max5_patcher----------
881008.3ocuXszaiaCD9r8uhA5rqAeHIa0aAMaAVf1S6hdoYQAsDiL6JQZHQ2M
89YWr+2KeX4vjnjXKKkKhhiGQ9MeyCNz+X9rnMp63sQvuB+MLa1OlOalSjUvrC
90ymEUytKuh05TKJWUWyk5nE9eSyuS6jesvHu4F4MxOuUzB6X57sPKWVzBLXiP
91xZtGj6q2vafaaT0.BzJfjj.p8ZPukazsQvpfcpFs8mXR3plh8BoBxURIOWyK
92rxspZ0YI.eTCEh5Vqp+wGtFXZMKe6CZc3yWZwTdCmYW.BBkdiby8v0r+ST.W
93sD9SdUkn8FYspPbqvnBNFtZWiUyLmleJWo0vuKzeuj2vpJLaWA7YiE7wREui
94FpDFDp1KcbAFcP5sJoVxp4NB5Jq40ougIDxJt1wo3GDZHiNocKhiIExx+owv
95AdOEAksDs.RRrOoww1Arc.9RvN2J9tamwjkcqknvAE0l+8WnjHqreNet8whK
96z6mukIK4d+Xknv3jstvJs8EirMMhxsZIusET25jXbX8xczIl5xPVxhPcTGFu
97xNDu9rXtUCg37g9Q8Yc+EuofIYmg8QdkPCrOnXsaHwYs3rWx9PGsO+pqueG2
98uNQBqWFh1X7qQG+3.VHcHrfO1nyR2TlqpTM9MDsLKNCQVz6KO.+Sfc5j1Ykj
99jzkn2jwNDRP7LVb3d9LtoWBAOnvB92Le6yRmZ4UF7YpQhiFi7A5Ka8zXhKdA
1004r9TRGG7V4COiSbAJKdXrWNhhF0hNUh7uBa4Mba0l7JUK+omjDMwkSn95Izr
101TOwkdp7W.oPRmNRQsiKeu4j3CkfVgt.NYPEYqMGvvJ48vIlPiyzrIuZskWIS
102xGJPcmPiWOfLodybH3wjPbMYwlbFIMNHPHFOtLBNaLSa9sGk1TxMzCX5KTa6
103WIH2ocxSdngM0QPqFRxyPHFsprrhGc9Gy9xoBjz0NWdR2yW9DUa2F85jG2v9
104FgTO4Q8qiC7fzzQNpmNpsY3BrYPVJBMJQ1uVmoItRhw9NrVGO3NMNzYZ+zS7
1053WTvTOnUydG5kHMKLqAOjTe7fN2bGSxOZDkMrBrGQ9J1gONBEy0k4gVo8qHc
106cxmfxVihWz6a3yqY9NazzUYkua9UnynadOtogW.JfsVGRVNEbWF8I+eHtcwJ
107+wLXqZeSdWLo+FQF6731Tva0BISKTx.cLwmgJsUTTvkg1YsnXmxDge.CDR7x
108D6YmX6fMznaF7kdczmJXwm.XSOOrdoHhNA7GMiZYLZZR.+4lconMaJP6JOZ8
109ftCs1YWHZI3o.sIXezX5ihMSuXzZtk3ai1mXRSczoCS32hAydeyXNEu5SHyS
110xqZqbd3ZLdera1iPqYxOm++v7SUSz
111-----------end_max5_patcher-----------
112 */
Note: See TracBrowser for help on using the repository browser.