Lesson 6--Microduino "Breathing Light"

来自Microduino Wikipedia
Jasonsheng讨论 | 贡献2014年2月11日 (二) 01:06的版本 (Created page with "{| style="width: 800px;" |- | ==Objective== The last two experiment uses the external device to generate PWM to control the LED, how to control the LED by program instead of t...")
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航搜索

Objective

The last two experiment uses the external device to generate PWM to control the LED, how to control the LED by program instead of the external device? This lesson will give you an example. This experiment implemented an led fadein dimming, named breathing lamp.

Equipment

  • Microduino-Core
  • Microduino-FT232R
  • Other hardware equipment
    • Breadboard Jumper one box
    • Breadboard one piece
    • LED Light-emitting diodes one
    • 220Ω resistor one
    • USB Data cable one

Experimental schematic

Using high level lighting, the output also need connect to Microduino's PWM I/O port. If use the low level lighting, it has the same result.

Program

int ledPin=11;//D3、D5、D6、D9、D10、D11 is Microduino PWM I/O output port
void setup()
{
}
void loop(){
  for(int fadeValue=0;fadeValue<=255;fadeValue+=5)
  //Increase PWM value, control the LED brightness by adjusting the value of fadeValue.
  {
    analogWrite(ledPin,fadeValue);   //Write the brightness value to LED.
    delay(30);                       //Keep the current brightness 30ms. 
  }
   for(int fadeValue=255;fadeValue>=0;fadeValue-=5)
   //Decrease PWM value,control the LED brightness by adjusting the value of fadeValue.
  {
    analogWrite(ledPin,fadeValue); //Write the brightness value to LED.
    delay(30);                     //Keep the current brightness 30ms. 
  }
  }
Program uses the loop statement, it's convenient to automatically control the brightness of the leds.

Result

LED lights from off to on softly then off, followed by cycle.

Video