0

Ok, I have a button with a small 24v Led inside. My goal is to control the light depending on the state of the button.

  • Quick press: toggle start/pause --> light on/off
  • Long press (1500ms) --> reset --> Light flash 1000ms

My question is: Is there a way to make this circuit using only one GPIO instead of two, one to control the LED and one that act as a signal?

Here is a small drawing of my circuit:

enter image description here

  • 1
    How were you intending to control/read the button (Bash, Assembler, C, Python etc.etc.)? You could try switching the GPIO between being an input and an output really quickly (so the LED would flash but fast enough that you'd not see it) but that's going to be tricky at best on the Pi and would probably be so unreliable that you'd rather use two pins. Is there a reason why you'd want to only use one pin and not consider a port expander, for example? – Roger Jones Feb 21 at 16:59
0

Using pythong you can dictate a time frame for the light to be kept on, and read the time frame the button is pressed and modify the lights output from that. Personally though id recomend a much smaller voltage switch, then you could pull 3.3v or 5v offf the gpio, and output to the gpio. I dont think you will find a means of 1 wire control for that many variables. You have to read button press(Vin, gnd, and Vout) plus led control(Vin only of its part of the Vin from the switch)

0

To obtain this function, you have to implement this in softwear,simply create swith monitering thread in your programing language.

0

You can implement something like SPI or 1-wire protocol.

You should send PWM signal with low duty cycle (<10%) when the led is off, and high (>80%) for ON state. By adding some transistor/mosfet/optocoupler you will be able to drive the led with an external 24V supply, additionally with some basic electronics elements your are able to flatten the PWM signal and keep it consistently low (under 0.7V) then the diobe/transistor remains closed so you can eliminate the flashing.

In this case your GPIO pin will act as a clock and the button will pull the signal up or down when the button is pushed. Then on RPi side you should watch for changes - differences from the clock - if the the signal was altered (pulled up or down) then your code can detect and handle the key press.

However, this solution relays on the assumption that the GPIO is able to work in output and input mode simultaneously.

Alternatively you can use GPIO expander board (via I2C), or add a micro controller (Arduino Pico/Nano or a single ATTiny85 chip) to build your own "Serial button board".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.