点亮led灯

来自Microduino Wikipedia
Pkj讨论 | 贡献2014年5月5日 (一) 07:41的版本 (Created page with "点亮LED灯 {| style="width: 800px;" |- | ==目的== 本教程将教大家如何用Processing来点亮LED灯。 ==设备== *'''Microduino-Core''' *'''Microduino-FT23...")
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航搜索

点亮LED灯

目的

本教程将教大家如何用Processing来点亮LED灯。

设备

  • 其他硬件设备
    • USB数据连接线 一根
    • 330欧电阻 一个
    • 面包板 一个
    • 跳线 一盒


原理图

ProcessingControlLED原理图.jpg


程序

见 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;
   }  
 }


步骤二:按着原理图搭建硬件环境,像这样:

ProcessingControlLED连接图.jpg


步骤三:下载代码并编译通过。


步骤四:运行后鼠标滑过灯泡上方或者点击灯泡,看看有什么反应。


结果

鼠标滑过灯泡上方,灯泡会亮起,离开会熄灭,Processing的动画效果是这样的:

鼠标滑过或点击灯泡:

ProcessingOverLEDON.jpg

鼠标离开或点击灯泡:

ProcessingOverLEDON.jpg

视频