“点亮led灯”的版本间的差异
(→调试) |
(→程序) |
||
| (未显示2个用户的4个中间版本) | |||
| 第1行: | 第1行: | ||
| − | + | {{Language | Lighten_Led}} | |
| − | |||
{| style="width: 800px;" | {| style="width: 800px;" | ||
|- | |- | ||
| 第9行: | 第8行: | ||
==设备== | ==设备== | ||
| − | *'''[[Microduino-Core]]''' | + | *'''[[Microduino-Core/zh]]''' |
| − | *'''[[Microduino- | + | *'''[[Microduino-USBTTL/zh]]''' |
*其他硬件设备 | *其他硬件设备 | ||
| 第27行: | 第26行: | ||
==程序== | ==程序== | ||
| − | + | [https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Processing/LEDButtonByOver LEDButtonByOver] | |
| − | LEDButtonByClick | + | [https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Processing/LEDButtonByClick LEDButtonByClick] |
注意:代码里包含图片请不要丢掉 | 注意:代码里包含图片请不要丢掉 | ||
| 第51行: | 第50行: | ||
在LEDButtonByOver的代码中实现的是鼠标经过点亮小灯 | 在LEDButtonByOver的代码中实现的是鼠标经过点亮小灯 | ||
| − | + | Mouse over: | |
// When the mouse is moved, the state of the button is toggled. | // When the mouse is moved, the state of the button is toggled. | ||
2014年10月29日 (三) 07:03的最新版本
| Language | English |
|---|
目的本教程将教大家如何用Processing来点亮LED灯。 设备
原理图
程序注意:代码里包含图片请不要丢掉 调试步骤一:按着原理图搭建硬件环境,像这样:
步骤二:解释一下代码: // Declaring two variable of type PImage, a class available to us from the Processing core library. PImage LEDON, LEDOFF; //load two img
LEDON = loadImage("LEDON.png");
LEDOFF = loadImage("LEDOFF.png");
在LEDButtonByOver的代码中实现的是鼠标经过点亮小灯 Mouse over: // When the mouse is moved, the state of the button is toggled.
void mouseMoved() {
if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h) {
button = true;
}
else {
button = false;
}
}
在LEDButtonByClick的代码中实现的是鼠标点击点亮小灯 Mouse Click: // When the mouse is pressed, the state of the button is toggled.
void mousePressed() {
if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h) {
button = !button;
}
}
步骤三:下载代码并编译通过。
结果鼠标滑过灯泡上方,灯泡会亮起,离开会熄灭,Processing的动画效果是这样的: 鼠标滑过或点击灯泡: 鼠标离开或点击灯泡: 视频 |



