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

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

First release to Xenial

File size: 5.1 KB
Line 
1/*
2  Graph
3
4 A simple example of communication from the Arduino board to the computer:
5 the value of analog input 0 is sent out the serial port.  We call this "serial"
6 communication because the connection appears to both the Arduino and the
7 computer as a serial port, even though it may actually use
8 a USB cable. Bytes are sent one after another (serially) from the Arduino
9 to the computer.
10
11 You can use the Arduino serial monitor to view the sent data, or it can
12 be read by Processing, PD, Max/MSP, or any other program capable of reading
13 data from a serial port.  The Processing code below graphs the data received
14 so you can see the value of the analog input changing over time.
15
16 The circuit:
17 Any analog input sensor is attached to analog in pin 0.
18
19 created 2006
20 by David A. Mellis
21 modified 9 Apr 2012
22 by Tom Igoe and Scott Fitzgerald
23
24 This example code is in the public domain.
25
26 http://www.arduino.cc/en/Tutorial/Graph
27 */
28
29void setup() {
30  // initialize the serial communication:
31  Serial.begin(9600);
32}
33
34void loop() {
35  // send the value of analog input 0:
36  Serial.println(analogRead(A0));
37  // wait a bit for the analog-to-digital converter
38  // to stabilize after the last reading:
39  delay(2);
40}
41
42/* Processing code for this example
43
44 // Graphing sketch
45
46
47// This program takes ASCII-encoded strings
48// from the serial port at 9600 baud and graphs them. It expects values in the
49// range 0 to 1023, followed by a newline, or newline and carriage return
50
51// Created 20 Apr 2005
52// Updated 24 Nov 2015
53// by Tom Igoe
54// This example code is in the public domain.
55
56import processing.serial.*;
57
58Serial myPort;        // The serial port
59int xPos = 1;         // horizontal position of the graph
60float inByte = 0;
61
62void setup () {
63  // set the window size:
64  size(400, 300);
65
66  // List all the available serial ports
67  // if using Processing 2.1 or later, use Serial.printArray()
68  println(Serial.list());
69
70  // I know that the first port in the serial list on my mac
71  // is always my  Arduino, so I open Serial.list()[0].
72  // Open whatever port is the one you're using.
73  myPort = new Serial(this, Serial.list()[0], 9600);
74
75  // don't generate a serialEvent() unless you get a newline character:
76  myPort.bufferUntil('\n');
77
78  // set inital background:
79  background(0);
80}
81void draw () {
82  // draw the line:
83  stroke(127, 34, 255);
84  line(xPos, height, xPos, height - inByte);
85
86  // at the edge of the screen, go back to the beginning:
87  if (xPos >= width) {
88    xPos = 0;
89    background(0);
90  } else {
91    // increment the horizontal position:
92    xPos++;
93  }
94}
95
96
97void serialEvent (Serial myPort) {
98  // get the ASCII string:
99  String inString = myPort.readStringUntil('\n');
100
101  if (inString != null) {
102    // trim off any whitespace:
103    inString = trim(inString);
104    // convert to an int and map to the screen height:
105    inByte = float(inString);
106    println(inByte);
107    inByte = map(inByte, 0, 1023, 0, height);
108  }
109}
110
111*/
112
113/* Max/MSP v5 patch for this example
114 ----------begin_max5_patcher----------
1151591.3oc0YszbaaCD9r7uBL5RalQUAO3CvdyS5zVenWZxs5NcfHgjPCIfJIT
116RTxj+6AOHkoTDooroUs0AQPR73a+1cwtK3WtZxzEpOwqlB9YveAlL4KWMYh6
117Q1GLo99ISKXeJMmU451zTUQAWpmNy+NM+SZ2y+sR1l02JuU9t0hJvFlNcMPy
118dOuBv.U5Rgb0LPpRpYBooM3529latArTUVvzZdFPtsXAuDrrTU.f.sBffXxL
119vGE50lIHkUVJXq3fRtdaoDvjYfbgjujaFJSCzq4.tLaN.bi1tJefWpqbO0uz
1201IjIABoluxrJ1guxh2JfPO2B5zRNyBCLDFcqbwNvuv9fHCb8bvevyyEU2JKT
121YhkBSWPAfq2TZ6YhqmuMUo0feUn+rYpY4YtY+cFw3lUJdCMYAapZqzwUHX8S
122crjAd+SIOU6UBAwIygy.Q1+HAA1KH6EveWOFQlitUK92ehfal9kFhUxJ3tWc
123sgpxadigWExbt1o7Ps5dk3yttivyg20W0VcSmg1G90qtx92rAZbH4ez.ruy1
124nhmaDPidE07J+5n2sg6E6oKXxUSmc20o6E3SPRDbrkXnPGUYE.i5nCNB9TxQ
125jG.G0kCTZtH88f07Rt0ZMMWUw8VvbKVAaTk6GyoraPdZff7rQTejBN54lgyv
126HE0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ybE8ZODf4fV8t9qW0zYxq.YJfTosj1bv0xc.SaC0+AV
1449V9L.KKyV3SyTcRtmzi6rO.O16USvts4B5xe9EymDvebK0eMfW6+NIsNlE2m
145eqRyJ0utRq13+RjmqYKN1e.4d61jjdsauXe3.2p6jgi9hsNIv97CoyJ01xzl
146c3ZhUCtSHx3UZgjoEJYqNY+hYs5zZQVFW19L3JDYaTlMLqAAt1G2yXlnFg9a
14753L1FJVcv.cOX0dh7mCVGCLce7GFcQwDdH5Ta3nyAS0pQbHxegr+tGIZORgM
148RnMj5vGl1Fs16drnk7Tf1XOLgv1n0d2iEsCxR.eQsNOZ4FGF7whofgfI3kES
1491kCeOX5L2rifbdu0A9ae2X.V33B1Z+.Bj1FrP5iFrCYCG5EUWSG.hhunHJd.
150HJ5hhnng3h9HPj4lud02.1bxGw.
151-----------end_max5_patcher-----------
152
153 */
Note: See TracBrowser for help on using the repository browser.