Micro:bit Breathing LED
Now I’m going to use micro:bit to make a breathing light. The breathing light means that the light changes gradually from bright to dark under the control of a micro:bit, and it feels like a person is breathing. It is widely used in mobile phones and has become one of the selling points of new mobile phones of major brands, acting as a notification reminder. First look at the effect:
Is the effect of blinking beautiful? We will use two bricks for programming:
1. Set the brightness brick
The brightness setting brick is in the LED category. It is used to set the brightness of the current LED dot matrix. The brightness has a total of 256 levels from 0 to 255, 0 is the darkest without any light, and 255 is the brightest.
It’s in the loops category and is used to precisely control the times of repeating. n is the times of repeating. If n is 1, then repeating once is executed, and if n is 5, the repeating is executed 5 times.
1. We need to control the brightness to achieve the effect of the breathing light. The effect of the breathing light is actually the process of the brightness from weak to strong and then from strong to weak, so we need to constantly change the brightness.
2. Because the maximum brightness is 255, we can increase the brightness of the led dot matrix from 0 to 255 in 5 times, and the value of each increasing is 255/5=51, and the weakening effect is the same. Coding:
1.Go to MakeCode editor（https://makecode.microbit.org/)
2.Show icon in the on-start brick.
3.Create a variable named brightness.
4.Set the brightness value in forever brick.
5.Create another loop, if brightness is less than 255, repeat 5 times, and increasing the brightness by 51 each time, then pause for 200ms, if brightness is equal to 255, repeat 5 times again, and decreasing brightness by 51 each time, pause for 200ms.
If you have any ideas or opinions, please feel free to contact us via email@example.com.
Share this post
About the Author
ELECFREAKS focuses on microbit and publishes interesting articles
- Micro bit supplier
- Wholesale Suppliers
- Micro bit tutorial
- Micro bit classroom pack
- Mcorbit Environment Monitoring
- TPBot car
- Micro:bit car
- AI Lens
- Micor:bit AI Lens
- Microbit gyroscope
- Micro:bit LEDs
- BBC micro:bit
- Micro:bit Manipulator
- Wukong board
- Micro:bit Motorcycle
- Nezha breakout
- Micro:bit DIY
- 360° servos
- AI Lens
- Retro Arcade
- Microbit programming