这里会显示出您选择的修订版和当前版本之间的差别。
两侧同时换到之前的修订记录前一修订版后一修订版 | 前一修订版 | ||
learing:examples:physicalpixel [2017/04/07 10:03] – 外部编辑 127.0.0.1 | learing:examples:physicalpixel [2023/06/07 04:23] (当前版本) – 外部编辑 127.0.0.1 | ||
---|---|---|---|
行 1: | 行 1: | ||
+ | ====== 物理像素 ====== | ||
+ | <WRAP left round info 65%> | ||
+ | 这个例子演示了使用arduino接收来自电脑的数据。收到 H 字符的时候点亮LED,收到 | ||
+ | |||
+ | 数据使用arduino自带的串口监视器发送,也可以使用processing(代码在下面)。 | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | <WRAP left round box 100%> | ||
+ | ===== ALPHA 8F328D-U核心 ===== | ||
+ | |||
+ | ==== 硬件 ==== | ||
+ | * [[ocrobot: | ||
+ | * [[ocrobot: | ||
+ | * [[ocrobot: | ||
+ | |||
+ | ==== 搭建电路 ==== | ||
+ | |||
+ | - ALPHA 11 LED模块插入并行扩展版1号槽位。 | ||
+ | - ALPHA 8F328D-U模块插入并行扩展板2号槽位。 | ||
+ | - USB线连接计算机与ALPHA 8F328D-U。 | ||
+ | |||
+ | ==== 代码 ==== | ||
+ | </ | ||
+ | |||
+ | <WRAP left round box 100%> | ||
+ | ===== MangoII ===== | ||
+ | |||
+ | ==== 硬件要求 ==== | ||
+ | |||
+ | |Arduino| | ||
+ | |电位计| | ||
+ | |||
+ | ==== 软件要求 ==== | ||
+ | |||
+ | |||
+ | Processing | ||
+ | |||
+ | 连接LED到13号脚(或者不连接,使用arduino自带的13号引脚的LED)。 | ||
+ | |||
+ | |||
+ | |||
+ | ==== Code ==== | ||
+ | |||
+ | |||
+ | <code cpp>/* | ||
+ | Physical Pixel | ||
+ | |||
+ | */ | ||
+ | |||
+ | const int ledPin = 13; // LED连接的引脚 | ||
+ | int incomingByte; | ||
+ | |||
+ | void setup() { | ||
+ | // 串口通信: | ||
+ | Serial.begin(9600); | ||
+ | // LED引脚输出: | ||
+ | pinMode(ledPin, | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | // 监听串口数据: | ||
+ | if (Serial.available() > 0) { | ||
+ | // 读串口缓冲区第一个字节 : | ||
+ | incomingByte = Serial.read(); | ||
+ | // 如果是大写字母H(ASCII码值是72), | ||
+ | if (incomingByte == ' | ||
+ | digitalWrite(ledPin, | ||
+ | } | ||
+ | //如果是 L (ASCII值是76) 熄灭 LED: | ||
+ | if (incomingByte == ' | ||
+ | digitalWrite(ledPin, | ||
+ | } | ||
+ | } | ||
+ | }</ | ||
+ | |||
+ | |||
+ | | ||
+ | |||
+ | <code cpp> // mouseover serial | ||
+ | |||
+ | |||
+ | |||
+ | | ||
+ | |||
+ | float boxX; | ||
+ | float boxY; | ||
+ | int boxSize = 20; | ||
+ | | ||
+ | |||
+ | | ||
+ | |||
+ | void setup() | ||
+ | | ||
+ | boxX = width/2.0; | ||
+ | boxY = height/2.0; | ||
+ | | ||
+ | |||
+ | // | ||
+ | // 选择arduino连接的串口. 列表第一个是port # | ||
+ | | ||
+ | |||
+ | // 打开串口 | ||
+ | // 波特率9600bps | ||
+ | port = new Serial(this, | ||
+ | |||
+ | } | ||
+ | |||
+ | void draw() | ||
+ | | ||
+ | | ||
+ | |||
+ | // 检测鼠标是否在方块外面 | ||
+ | if (mouseX > boxX-boxSize && mouseX < boxX+boxSize && | ||
+ | | ||
+ | | ||
+ | // 在方块周围画线,并且涂不同的颜色: | ||
+ | | ||
+ | | ||
+ | // 发送H表示鼠标移出方块了: | ||
+ | | ||
+ | | ||
+ | else { | ||
+ | // return the box to it's inactive state: | ||
+ | | ||
+ | | ||
+ | // 发送' | ||
+ | | ||
+ | | ||
+ | } | ||
+ | |||
+ | // | ||
+ | | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | 下载好程序之后,移动鼠标到方块里,看LED亮灭变化 | ||
+ | </ | ||
+ | 。 |