mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-15 12:29:26 +01:00
Merge pull request #4220 from agdl/communicationExamples
Fixed processing code for Processing 3
This commit is contained in:
commit
8e6a30e00c
@ -49,7 +49,7 @@ void loop() {
|
||||
// range 0 to 1023, followed by a newline, or newline and carriage return
|
||||
|
||||
// Created 20 Apr 2005
|
||||
// Updated 18 Jan 2008
|
||||
// Updated 24 Nov 2015
|
||||
// by Tom Igoe
|
||||
// This example code is in the public domain.
|
||||
|
||||
@ -57,6 +57,7 @@ void loop() {
|
||||
|
||||
Serial myPort; // The serial port
|
||||
int xPos = 1; // horizontal position of the graph
|
||||
float inByte = 0;
|
||||
|
||||
void setup () {
|
||||
// set the window size:
|
||||
@ -78,8 +79,20 @@ void loop() {
|
||||
background(0);
|
||||
}
|
||||
void draw () {
|
||||
// everything happens in the serialEvent()
|
||||
// draw the line:
|
||||
stroke(127, 34, 255);
|
||||
line(xPos, height, xPos, height - inByte);
|
||||
|
||||
// at the edge of the screen, go back to the beginning:
|
||||
if (xPos >= width) {
|
||||
xPos = 0;
|
||||
background(0);
|
||||
} else {
|
||||
// increment the horizontal position:
|
||||
xPos++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void serialEvent (Serial myPort) {
|
||||
// get the ASCII string:
|
||||
@ -89,22 +102,9 @@ void loop() {
|
||||
// trim off any whitespace:
|
||||
inString = trim(inString);
|
||||
// convert to an int and map to the screen height:
|
||||
float inByte = float(inString);
|
||||
inByte = float(inString);
|
||||
println(inByte);
|
||||
inByte = map(inByte, 0, 1023, 0, height);
|
||||
|
||||
// draw the line:
|
||||
stroke(127,34,255);
|
||||
line(xPos, height, xPos, height - inByte);
|
||||
|
||||
// at the edge of the screen, go back to the beginning:
|
||||
if (xPos >= width) {
|
||||
xPos = 0;
|
||||
background(0);
|
||||
}
|
||||
else {
|
||||
// increment the horizontal position:
|
||||
xPos++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,6 +85,7 @@ void loop() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
/* Max/MSP patch for this example
|
||||
|
Loading…
x
Reference in New Issue
Block a user