@@ -44,71 +44,71 @@ void loop() {
4444 // Graphing sketch
4545
4646
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 18 Jan 2008
53- // by Tom Igoe
54- // This example code is in the public domain.
55-
56- import processing.serial.*;
57-
58- Serial myPort; // The serial port
59- int xPos = 1; // horizontal position of the graph
60-
61- void setup () {
62- // set the window size:
63- size(400, 300);
64-
65- // List all the available serial ports
66- // if using Processing 2.1 or later, use Serial.printArray()
67- println(Serial.list());
68-
69- // I know that the first port in the serial list on my mac
70- // is always my Arduino, so I open Serial.list()[0].
71- // Open whatever port is the one you're using.
72- myPort = new Serial(this, Serial.list()[0], 9600);
73-
74- // don't generate a serialEvent() unless you get a newline character:
75- myPort.bufferUntil('\n');
76-
77- // set inital background:
78- background(0);
79- }
80- void draw () {
81- // everything happens in the serialEvent()
82- }
83-
84- void serialEvent (Serial myPort) {
85- // get the ASCII string:
86- String inString = myPort.readStringUntil('\n');
87-
88- if (inString != null) {
89- // trim off any whitespace:
90- inString = trim(inString);
91- // convert to an int and map to the screen height:
92- float inByte = float(inString);
93- inByte = map(inByte, 0, 1023, 0, height);
94-
95- // draw the line:
96- stroke(127,34,255);
97- line(xPos, height, xPos, height - inByte);
98-
99- // at the edge of the screen, go back to the beginning:
100- if (xPos >= width) {
101- xPos = 0;
102- background(0);
103- }
104- else {
105- // increment the horizontal position:
106- xPos++;
107- }
108- }
109- }
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
11050
111- */
51+ // Created 20 Apr 2005
52+ // Updated 24 Nov 2015
53+ // by Tom Igoe
54+ // This example code is in the public domain.
55+
56+ import processing.serial.*;
57+
58+ Serial myPort; // The serial port
59+ int xPos = 1; // horizontal position of the graph
60+ float inByte = 0;
61+
62+ void 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+ }
81+ void 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+
97+ void 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+ */
112112
113113/* Max/MSP v5 patch for this example
114114 ----------begin_max5_patcher----------
0 commit comments