/* Code for Processing 使用Processing读取模拟传感器数值控制球的横向移动 By Lei Gao (Whaleforest) http://imlab.cn/whale & http://imlab.cn/forum 2009/02/20 */ import processing.serial.*; Serial myPort; int val; void setup() { size(300,200); frameRate(60); println(Serial.list()); //列出电脑中所有串口 myPort = new Serial(this, Serial.list()[1], 9600); /*根据实际情况更改大括号中的数字,选择arduino对应的串口, 例如arduino在我的电脑中占用第二个串口,大括号中就写1,依此类推。*/ } void draw(){ background(0); if ( myPort.available() > 0) { val = myPort.read(); } print(val); print(",");//print函数可以让我们观察输入数据的变化 smooth(); ellipse(val,50,30,30);//y轴保持数值(50)不变,变量val控制圆球在x轴上移动 }