标题:
processing从串口读数据
[打印本页]
作者:
51hei小林
时间:
2016-9-24 22:58
标题:
processing从串口读数据
float
px
=
0.0
;
import
processing.serial.
*
;
Serial port;
float
val;
void
setup(){
size(
440
,
220
);
fill(
255
,
20
,
50
);
println(Serial.list());
String
arduinoPort
=
Serial.list()[
1
];
port
=
new
Serial(
this
,arduinoPort,
9600
);
}
void
draw(){
background(
0
);
stroke(
255
);
if
(port.available()
>
0
){
val
=
port.read();
val
=
map(val,
0
,
255
,
0
,height);
}
rect(
40
,val
-10
,
360
,
20
);
}
/*
int sensorPin = A0;
int val = 0;
void setup(){
Serial.begin(9600);
}
void loop(){
val = analogRead(sensorPin);
val = map(val,0,1023,0,255);
Serial.write(val);
//Serial.println();
//Serial.println(val);
delay(100);
}
*/
import
processing.serial.
*
;
Serial port;
float
val;
int
x;
float
easing
=
0.05
;
float
easedVal;
void
setup(){
size(
440
,
440
);
frameRate(
30
);
smooth();
fill(
255
,
20
,
50
);
println(Serial.list());
String
arduinoPort
=
Serial.list()[
1
];
port
=
new
Serial(
this
,arduinoPort,
9600
);
background(
0
);
}
void
draw(){
if
(port.available()
>
0
){
val
=
port.read();
val
=
map(val,
0
,
255
,
0
,height);
}
float
targetVal
=
val;easedVal += (targetVal-easedVal) * easing;
stroke(
0
);
line(x,
0
,x,height);
stroke(
255
);
line(x
+1
,
0
,x
+1
,height);
line(x,
220
,x,val);
line(x,
440
,x,easedVal
+220
);
x
++
;
if
(x
>
width){
x
=
0
;
}
}
/*
int sensorPin = A0;
int val = 0;
void setup(){
Serial.begin(9600);
}
void loop(){
val = analogRead(sensorPin);
val = map(val,0,1023,0,255);
Serial.write(val);
//Serial.println();
//Serial.println(val);
delay(100);
}
*/
import
processing.serial.
*
;
Serial port;
float
val;
float
angle;
float
radius;
void
setup(){
size(
440
,
440
);
frameRate(
30
);
smooth();
strokeWeight(
2
);
fill(
255
,
20
,
50
);
println(Serial.list());
String
arduinoPort
=
Serial.list()[
1
];
port
=
new
Serial(
this
,arduinoPort,
9600
);
background(
0
);
}
void
draw(){
if
(port.available()
>
0
){
val
=
port.read();
radius
=
map(val,
0
,
255
,
0
,height
*
0.45
);
}
int
middleX
=
width/
2
;
int
middleY
=
height/
2
;
float
x
=
middleX
+
cos(angle)
*
height/
2
;
float
y
=
middleY
+
sin(angle)
*
height/
2
;
stroke(
0
);
line(middleX,middleY,x,y);
x
=
middleX
+
cos(angle)
*
radius;
y
=
middleY
+
sin(angle)
*
radius;
stroke(
255
);
line(middleX,middleY,x,y);
angle
+=
0.01
;
}
/*
int sensorPin = A0;
int val = 0;
void setup(){
Serial.begin(9600);
}
void loop(){
val = analogRead(sensorPin);
val = map(val,0,1023,0,255);
Serial.write(val);
//Serial.println();
//Serial.println(val);
delay(100);
}
*/
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1