“Led花样流水”的版本间的差异
(→程序) |
|||
| (未显示同一用户的1个中间版本) | |||
| 第8行: | 第8行: | ||
==设备== | ==设备== | ||
| − | *'''[[Microduino-Core]]''' | + | *'''[[Microduino-Core/zh]]''' |
| − | *'''[[Microduino- | + | *'''[[Microduino-USBTTL/zh]]''' |
*其他硬件设备 | *其他硬件设备 | ||
| 第17行: | 第17行: | ||
**面包板 一个 | **面包板 一个 | ||
**跳线 一盒 | **跳线 一盒 | ||
| − | |||
| − | |||
==原理图== | ==原理图== | ||
| 第28行: | 第26行: | ||
==程序== | ==程序== | ||
| − | https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Processing/sketch_8LEDs | + | [https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Processing/sketch_8LEDs sketch_8LEDs] |
注意:代码里包含图片请不要丢掉 | 注意:代码里包含图片请不要丢掉 | ||
2014年10月29日 (三) 07:05的最新版本
| Language | English |
|---|
目的本教程将教大家如何用Processing来控制8个LED灯,想让谁亮就谁亮。 设备
原理图
程序注意:代码里包含图片请不要丢掉 调试步骤一:按着原理图搭建硬件环境,像这样:
在本例中有两个代码文件: LED:LED灯的对象 //定义的对象内变量 int xpos;
int ypos;
int w = 50;
int h = 50;
PImage LEDState=loadImage("LEDOFF.png");
int ledPin;
boolean button = false;
LED(int xpos_, int ypos_, int ledPin_) {
xpos = xpos_;
ypos = ypos_;
ledPin=ledPin_;
}
//显示函数 void display() {
if(button) {
LEDState=loadImage("LEDON.png");
} else {
LEDState=loadImage("LEDOFF.png");
}
image(LEDState,xpos,ypos);
}
//鼠标点击函数,判断点击的LED,点击后切换按钮状态和LED灯的状态 void mousePressed() {
for (int i = 0; i < leds.length; i ++ ) {
x=leds[i].xpos;
y=leds[i].ypos;
w=leds[i].w;
h=leds[i].h;
if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h) {
leds[i].button = !leds[i].button;
}
}
}
步骤三:下载代码并编译通过。
结果屏幕上会显示8个灯泡,你让那个灯泡亮,实际对应的LED灯就会亮 视频 |


