“点亮led灯”的版本间的差异
(Created page with "点亮LED灯 {| style="width: 800px;" |- | ==目的== 本教程将教大家如何用Processing来点亮LED灯。 ==设备== *'''Microduino-Core''' *'''Microduino-FT23...") |
(→设备) |
||
| 第14行: | 第14行: | ||
*其他硬件设备 | *其他硬件设备 | ||
**USB数据连接线 一根 | **USB数据连接线 一根 | ||
| − | **330欧电阻 | + | **LED灯 一个 |
| − | **面包板 | + | **330欧电阻 一个 |
| − | **跳线 | + | **面包板 一个 |
| − | + | **跳线 一盒 | |
| − | |||
==原理图== | ==原理图== | ||
2014年5月5日 (一) 07:41的版本
点亮LED灯
目的本教程将教大家如何用Processing来点亮LED灯。 设备
原理图
程序见 LEDButtonByOver LEDButtonByClick
调试步骤一:解释一下代码: // 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");
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;
}
}
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的动画效果是这样的: 鼠标滑过或点击灯泡: 鼠标离开或点击灯泡: 视频 |


