Various Display of Led Lights

来自Microduino Wikipedia
Pkj讨论 | 贡献2014年5月27日 (二) 08:15的版本 (Created page with "{{Language | led花样流水}} {| style="width: 800px;" |- | ==Objective== This tutorial will control 8 LEDs via Processing. ==Equipment== *'''Microduino-Core''' *'''Mi...")
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航搜索
Language English

Objective

This tutorial will control 8 LEDs via Processing.

Equipment

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

Schematic

ProcessingControl8LEDSchematics.jpg

Program

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

Note:Don't drop the picture in program

Debug

Step 1:Set up hardware system, as follows:

ProcessingControl8LEDConnectionDiagram.jpg


Step 2:Explain the code:

There are two code files in this example:

LED object:

//Define the variable in object

 int xpos;
 int ypos;
 int w = 50;
 int h = 50;
 
 PImage LEDState=loadImage("LEDOFF.png");
 int ledPin;
 boolean button = false;


//Constructor function

 LED(int xpos_, int ypos_, int ledPin_) {
   xpos = xpos_;
   ypos = ypos_;
   ledPin=ledPin_;
 }

//Display function

 void display() {
   if(button) {
     LEDState=loadImage("LEDON.png");
   } else {
     LEDState=loadImage("LEDOFF.png");
   }
   image(LEDState,xpos,ypos);
 }


sketch_8LEDs:Main function

//Mouse click function, identify which LED was clicked, then change the button state and LED state after click.

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

Step 3: Compile the code and download it.

Step 4: Click several LED randomly, observe the result.

Result

8 LED will be displayed in screen, you can cotrol them.

ProcessingControl8LEDResult.jpg

Video