“点亮led灯”的版本间的差异
(Created page with "点亮LED灯 {| style="width: 800px;" |- | ==目的== 本教程将教大家如何用Processing来点亮LED灯。 ==设备== *'''Microduino-Core''' *'''Microduino-FT23...") |
(没有差异)
|
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的动画效果是这样的: 鼠标滑过或点击灯泡: 鼠标离开或点击灯泡: 视频 |