Lighten Led

From Microduino Wiki
Revision as of 07:59, 27 May 2014 by Pkj (talk) (Created page with "{{Language | 点亮led灯}} {| style="width: 800px;" |- | ==Objective== This tutorial will teach you how to use the Processing to light LED. ==Equipment== *'''Microduino-Co...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Language: English  • 中文

Objective

This tutorial will teach you how to use the Processing to light LED.

Equipment

  • Other equipment
    • USB cable one
    • LED one
    • 330Ω resistor one
    • Bread one
    • Breadboard Jumper onebox

Schematic

ProcessingControlLED原理图.jpg

Program

https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Processing/LEDButtonByOver

https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Processing/LEDButtonByClick

Note:Don't drop the picture in program

Debut

Step 1:Set up hardware system, as follows:

ProcessingControlLED连接图.jpg

Step 2:Explain the code:

// 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 movement will light the LED which was realized in 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;
   }
 }

Mouse click will light the LED which was realized in 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;
   }  
 }

Step 3:Compile the code and download it.


Step 4:After run, mouse move or click the LED, observe the result.

Result

Mouse move on the LED, it will light, and trun off when leave it. Processing'S animation effects:

ProcessingOverLEDON.jpg
ProcessingOverLEDOFF.jpg

Video