void loop()
{
static unsigned char head = 0;
static unsigned long lastTick = timer0_millis;
unsigned int i, j;
for (i = 0; i < ledNum; ++i) // Turn on the light first, then turn it off when the duty cycle reaches the switching point
{
if (ledPwm[i] == 0)
continue;
digitalWrite(leds[i], LOW);
}
ledPwm[head] = initPwm; // The water drop head is the brightest
for (i = 0; i < maxPwm; ++i) // Here is the PWM program for digital port simulation
{
for (j = 0; j < ledNum; ++j)
{
if (i == ledPwm[j])
digitalWrite(leds[j], HIGH);
}
delayMicroseconds(1);
}
// If the delay time has not expired, jump out first without moving the water droplets.
if (timer0_millis - lastTick < delayMs) // Since it uses a digital port to simulate PWM, the program has to run non-stop, so delay() cannot be used to delay, otherwise it will get stuck.
return;
lastTick = timer0_millis;
for (i = 0; i < ledNum; ++i) // Process the brightness of each light
{
ledPwm[i] = ledPwm[i] * deltaPercent / 100;
if (ledPwm[i] <= deltaPwm){ ledPwm[i] = 0; }
else { ledPwm[i] -= deltaPwm; }
if (i == head){ ledPwm[i] = initPwm; }
}
head = (head + 1) % ledNum; // Move the water dropper
}
Full version of LED "Meteor Shower" effect
Summarize:
1. We understand how PWM is implemented
2. LEDs will "deceive" our eyes at different frequencies. This is a common idea when playing with microcontrollers.
3. By analyzing the LED "meteor shower", we found that it is actually implemented using some simple processing methods and is not as complicated as we imagined.
4. There is a simple algorithm in LED "Meteor Shower". The algorithm is independent of the microcontroller and can also be implemented on other platforms (51, STM32, etc.). At the same time, the algorithm is also the soul of a program.
Previous article:Debugging methods for using new IC chips in microcontroller projects
Next article:(3) Another way to learn the basic components of button control LED lights
Recommended ReadingLatest update time:2024-11-22 20:22
- Popular Resources
- Popular amplifiers
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
- Intelligent Control Technology of Permanent Magnet Synchronous Motor (Written by Wang Jun)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- Another technical solution for power-type plug-in hybrid: A brief discussion on Volvo T8 plug-in hybrid technology
- He almost lost his job because he often listened to music with headphones?
- Simplifying Current Sensing: How to Design with Current Sense Amplifiers
- SJA1000
- Prize-winning live broadcast: How to reduce design errors? Registration for Mentor PCB online seminar opens on July 7!
- Share CC2541 Bluetooth clock settings
- Qixing Tianyu-The development trend of reflow soldering
- information
- Analysis of the structure and working principle of single chip microcomputer serial communication
- [Synopsys IP Resources] How to fully support electric vehicle virtualization verification from system to software
- Basic functions of linear charger