processing串口通讯

上传人:M****1 文档编号:589836570 上传时间:2024-09-11 格式:PPT 页数:8 大小:69.50KB
返回 下载 相关 举报
processing串口通讯_第1页
第1页 / 共8页
processing串口通讯_第2页
第2页 / 共8页
processing串口通讯_第3页
第3页 / 共8页
processing串口通讯_第4页
第4页 / 共8页
processing串口通讯_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《processing串口通讯》由会员分享,可在线阅读,更多相关《processing串口通讯(8页珍藏版)》请在金锄头文库上搜索。

1、Processing的串口通讯的串口通讯Processing的串口通讯的串口通讯l通过串口,可以读写,双向通讯。系统范例系统范例l学习系统自带的范例:lFile-examples关键语句分析关键语句分析l引用库:limport processing.serial.*;l定义变量lSerial myPort;l连接指定串口l String portName = Serial.list()0;l myPort = new Serial(this, portName, 9600);关键语句分析关键语句分析l判断串口是否有数据lmyPort.available() 0l获取串口数据lval = myP

2、ort.read(); l输出串口数据lmyPort.write(H); 范例范例1:import processing.serial.*;Serial myPort; / Create object from Serial classint val; / Data received from the serial portvoid setup() size(200, 200);String portName = Serial.list()0; myPort = new Serial(this, portName, 9600);void draw() if ( myPort.available

3、() 0) / If data is available, val = myPort.read(); / read it and store it in val background(255); / Set background to white if (val = 0) / If the serial value is 0, fill(0); / set fill to black else / If the serial value is not 0, fill(204); / set fill to light gray rect(50, 50, 100, 100);范例范例1中中ard

4、uino的代码的代码int switchPin = 4; / Switch connected to pin 4void setup() pinMode(switchPin, INPUT); / Set pin 0 as an input Serial.begin(9600);void loop() if (digitalRead(switchPin) = HIGH) / If switch is ON, Serial.print(1, BYTE); / send 1 to Processing else / If the switch is not ON, Serial.print(0, BYTE); / send 0 to Processing delay(100); / Wait 100 milliseconds练习:练习:l基础:做一个文字型的电子钟;l进阶:做一个文字加现状的电子钟。

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 建筑/环境 > 施工组织

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号