Maple Lesson 04 - Breathing LED experiment
ContentsObjectiveIn previous experiment, LED only has two states, on and off. This experiment implemented a led fade in dimming, named breathing lamp. EquipmentMicroduino-CoreSTM32 is an ARM development board using STM32F103CBT6 chip. It use special Upin7 interface, the size is similar with a coin and fully compatible other Microduino modules.
SchematicThis experiment uses PWM to control the LED. This method adjusts the digital signal (" 0 ", "1") value within a period of time that is the time of the duty ratio to control the brightness of LED. If the high voltage "1" lasts long time, the LED will light longer. For PWM's detailed information, please refer to: http://www.geek-workshop.com/thread-125-1-1.html But not all of the I/O ports can be used for the PWM, only several special port can be used. Microduino-CoreSTM32's PWM I/O ports:0,1,4,11,12,14(A0),15(A1),16(A2),17(A3),18(SDA),19(SCL),20(A6),21(A7), we can use the LED on board directly, because it connects to the D4 pin. You also can use other PWM port to try. Programint ledPin=4;// 0,1,4,11,12,14(A0),15(A1),16(A2),17(A3),18(SDA),19(SCL),20(A6),21(A7) is the PWM port
void setup()
{
pinMode(ledPin, PWM);
}
void loop(){
for(int fadeValue=0;fadeValue<=65535;fadeValue+=500)
//Control the PWM value using variable fadeValue, PWM will increase.
{
pwmWrite(ledPin,fadeValue); //Write the brightness level to LED
delay(30); //Set the during timer, the unit is ms
}
for(int fadeValue=65535;fadeValue>=0;fadeValue-=500)
//Control the PWM value using variable fadeValue, PWM will decrease.
{
pwmWrite(ledPin,fadeValue); //Write the brightness level to LED
delay(30); //Set the during timer, the unit is ms
}
delay(400);
} Grammar:
You need pay attention to that:Define the output as PWM mode, that is“pinMode(ledPin, PWM);” Debug
Video |