Ingenious! 1 GPIO Controls 2 LEDs to Display 4 States

Ingenious! 1 GPIO Controls 2 LEDs to Display 4 States

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):

Ingenious! 1 GPIO Controls 2 LEDs to Display 4 States

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:

Ingenious! 1 GPIO Controls 2 LEDs to Display 4 States

Circuit Analysis

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

Ingenious! 1 GPIO Controls 2 LEDs to Display 4 States

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

Ingenious! 1 GPIO Controls 2 LEDs to Display 4 States

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.

Ingenious! 1 GPIO Controls 2 LEDs to Display 4 States

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.

Ingenious! 1 GPIO Controls 2 LEDs to Display 4 States

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.

Ingenious! 1 GPIO Controls 2 LEDs to Display 4 States

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.Ingenious! 1 GPIO Controls 2 LEDs to Display 4 StatesENDReview of Previous Hot ArticlesGuide 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

Ingenious! 1 GPIO Controls 2 LEDs to Display 4 States

Ingenious! 1 GPIO Controls 2 LEDs to Display 4 States

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

Ingenious! 1 GPIO Controls 2 LEDs to Display 4 StatesIngenious! 1 GPIO Controls 2 LEDs to Display 4 StatesShareIngenious! 1 GPIO Controls 2 LEDs to Display 4 StatesCollectIngenious! 1 GPIO Controls 2 LEDs to Display 4 StatesLikeIngenious! 1 GPIO Controls 2 LEDs to Display 4 StatesView

Leave a Comment