Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to make a LED breathing lamp for raspberry pie python

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Today, I will talk to you about how to make an LED breathing light with Raspberry Pi python. Many people may not know much about it. In order to let everyone know more, Xiaobian summarized the following contents for everyone. I hope you can gain something according to this article.

breathing light

overview

Previous We control the brightness of an LED by controlling the output level of GPIO port. This time we control the brightness of the LED, the light gradually becomes bright from dark, and then gradually darkens from bright to dark, repeating the cycle, that is, the effect of breathing lights. Press Ctrl+C to end the program.

In this lesson, you will learn:

pulse width modulation technique

the required hardware

Raspberry Pi x1

breadboard x1

Dupont line x2

LED lamp x1

Name explanation

We know that the larger the current through the LED, the brighter the LED, the smaller the current, the darker the LED. If you can control the size of the output current, you can control the brightness of the LED. However, the pins of the Raspberry Pi do not have the function of directly adjusting the output current, so we must think of other ways. Here, we need to know the following two nouns:

Pulse Width Modulation (PWM)

Pulse width modulation (PWM) is a technique that uses digital means to obtain analog results. Digital controls are used to create square waves with levels that switch between high and low. Simply put, PWM technology is to continuously open and close the circuit and control the length of the time segment of the on-off duration, thus controlling the actual power obtained by the electrical appliance in the unit time. To put it simply, if your hand is fast enough, turn on the light switch and turn it off immediately, and if the interval is short enough, the filament will go dark before it is all lit up. You turn the light on and off again, and on and off again…If you keep the same frequency, the light should stay at a constant brightness. In theory, you could get different brightness levels by adjusting the ratio of how long the lights stay on and how long the lights stay off.

The duration of the "on time" is called the pulse width. To obtain different analog values, you can change the width of the pulse.

duty cycle

The proportion of the time during which electricity is applied in a pulse cycle.

wiring diagram

The first thing to do before starting to connect the hardware circuits is to turn off the Raspberry Pi computer and disconnect the power. Because if the Raspberry Pi motherboard is charged, plugging the circuit may cause the electronic components to burn, so be sure to remember that the motherboard must be powered off when connecting the circuit. This wiring diagram is exactly the same as the previous one (the first GPIO control LED lamp program).

The pictures were drawn by Fritzing. For more sample pictures, please visit Fritzing's official website.

circuit schematic diagram

Sample code screenshot Anti-indentation failure!!!

save the file as

breathing-light.py

And run it.

sudo python breathing-light.py

final effect

This article participates in the "OSC Source Creation Plan." Welcome you who are reading to join and share it together.

After reading the above, do you have any further understanding of how Raspberry Pi python makes an LED breathing light? If you still want to know more knowledge or related content, please pay attention to the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report