“Lesson 6--Microduino "Breathing Light"”的版本间的差异

来自Microduino Wikipedia
跳转至: 导航搜索
 
(未显示7个用户的12个中间版本)
第1行: 第1行:
{{Language|Lesson_6--The_Program_PWM_control_of_LED_brightness_--Breathing_light}}
+
{{Language|第六课--程序PWM控制LED亮度--呼吸灯}}
 
{| style="width: 800px;"
 
{| style="width: 800px;"
 
|-
 
|-
 
|
 
|
 
==Objective==
 
==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?
+
In the last two lessons we used external devices (a button and a potentiometer) to generate PWM to control the LED. From Lesson 1, we also learned how to turned an LED on and off using software. But how would we go about controlling an LED's brightness through PWM using software only? This lesson will teach you how to implement an LED "Breathing Light".
This lesson will give you an example. This experiment implemented an led fadein dimming, named breathing lamp.
 
  
 
==Equipment==
 
==Equipment==
第11行: 第10行:
 
*'''[[Microduino-FT232R]]'''
 
*'''[[Microduino-FT232R]]'''
 
*Other hardware equipment
 
*Other hardware equipment
**Breadboard Jumper            one box 
+
**1x Box of breadboard jumper wires             
**Breadboard               one piece 
+
**1x Breadboard                
**LED Light-emitting diodes    one
+
**1x LED  
**220Ω resistor           one
+
**1x 220Ω resistor      
**USB Data cable              one
+
**1x USB Data cable               
  
==Experimental schematic==
+
 
 +
[[File:lesson6All.jpg|600px|center|thumb]]
 +
 
 +
==Experiment Schematic==
 
[[File:lesson 6-schematic.jpg|600px|center|thumb]]
 
[[File:lesson 6-schematic.jpg|600px|center|thumb]]
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.
+
The schematic above uses a high level connection. Since we want the LED to be more than just on and off, we still need to connect the anode to a Microduino PWM I/O port. Using a low level connection achieves the same result.  
  
 
==Program==
 
==Program==
第26行: 第28行:
 
void setup()
 
void setup()
 
{
 
{
 +
pinMode(ledPin,OUTPUT);
 
}
 
}
void loop(){
+
void loop()
 +
{
 
   for(int fadeValue=0;fadeValue<=255;fadeValue+=5)
 
   for(int fadeValue=0;fadeValue<=255;fadeValue+=5)
 
   //Increase PWM value, control the LED brightness by adjusting the value of fadeValue.
 
   //Increase PWM value, control the LED brightness by adjusting the value of fadeValue.
第40行: 第44行:
 
     delay(30);                    //Keep the current brightness 30ms.  
 
     delay(30);                    //Keep the current brightness 30ms.  
 
   }
 
   }
  }
+
}
Program uses the loop statement, it's convenient to automatically control the brightness of the leds.
 
 
</source>
 
</source>
 +
This program uses for loops, which allows for convenient control of the brightness of the LEDs.
 +
 
==Result==
 
==Result==
LED lights from off to on softly then off, followed by cycle.
+
LED gradually goes from off to on, then off. It then repeats.
 +
 
 +
[[File:lesson6Result.jpg|600px|center|thumb]]
  
 
==Video==
 
==Video==
 +
http://v.youku.com/v_show/id_XNzA5OTk3MTU2.html
 
|}
 
|}

2015年7月13日 (一) 08:16的最新版本

Language English

Objective

In the last two lessons we used external devices (a button and a potentiometer) to generate PWM to control the LED. From Lesson 1, we also learned how to turned an LED on and off using software. But how would we go about controlling an LED's brightness through PWM using software only? This lesson will teach you how to implement an LED "Breathing Light".

Equipment


Lesson6All.jpg

Experiment Schematic

Lesson 6-schematic.jpg

The schematic above uses a high level connection. Since we want the LED to be more than just on and off, we still need to connect the anode to a Microduino PWM I/O port. Using a low level connection achieves the same result.

Program

int ledPin=11;//D3、D5、D6、D9、D10、D11 is Microduino PWM I/O output port
void setup()
{
pinMode(ledPin,OUTPUT);
}
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. 
  }
}

This program uses for loops, which allows for convenient control of the brightness of the LEDs.

Result

LED gradually goes from off to on, then off. It then repeats.

Lesson6Result.jpg

Video

http://v.youku.com/v_show/id_XNzA5OTk3MTU2.html