
Many electronic products have status indicator lights, such as TVs:
-
Standby state lights upred light
-
Power on state lights upgreen light
It is very simple to implement, just control two GPIOs of the microcontroller (MCU):

However, resources are always tight, and sometimes you may encounter situations where there are not enough GPIOs.If only using 1 GPIO, can we control two LED lights?To achieve 4 states:
-
Red lighton, green lightoff
-
Red lightoff, green lighton
-
Both off
-
Both on
Directly to the circuit:

Circuit Analysis
1. When the red light is on and the green light is off, GPIO1 outputs a 5V high level:

2. When the red light is off and the green light is on, GPIO1 outputs a 0V low level:

3. When both the red and green lights are off, GPIO1 is set to high impedance. At this time, since the total forward voltage drop requirement of the two LEDs is greater than 5V, neither LED will conduct.

4. When both the red and green lights are on, GPIO1 alternates between high and low levels. As long as the frequency of switching between high and low levels is high enough, due to the persistence of vision, the human eye perceives both lights as constantly on.

Precautions
When using this circuit, pay attention to the current driving capability of the MCU’s GPIO.The current that the GPIO can withstand must be greater than the current flowing through the LED lights.The following screenshot is from the STM32 chip’s datasheet, which shows that its GPIO can drive or sink 8mA of current.

Conclusion
1 GPIO controls 2 LEDs to display 4 states, the implementation of the circuit itself is ingenious.1 GPIO controls 2 LEDs to display 4 states, I wonder if this master below can come up with a brilliant couplet.Source: Circuit AhThis article is reproduced from Circuit Ah, and the views in the article are neutral to the Electronic Engineering Magazine, for learning and communication purposes only.
END▼Review of Previous Hot Articles▼Guide for Communication Professionals on “Unemployment”
50HZ Direct Elimination Method
Eight Common Uses of Diodes
Huawei’s 3D Stacked Chips, Temporary Fix? Fundamental Solution?
4D Automotive Radar’s “Catfish Effect”
Evaluation Center


Long press the image, scan the code to receive for free

Share
Collect
Like
View