I’m trying to add a low battery LED indicator to the python code created in the lipopi page here.
I do not know how to code but can sometimes gets by doing simple things like this. Using this page that I found about setting up a blinking LED I’m trying to modify the original file to include an LED blink output when the low battery indicator turns on.
What I’ve done:
Added this line to add an event ‘low_battery_ledblink’ in the event that the ‘low_battery_pin’ is triggered
GPIO.add_event_detect(lipopi['low_battery_pin'], GPIO.FALLING, callback=lipopi_low_battery_ledblink, bouncetime=300)
Added this to define the ‘low_battery_ledblink’ function. (this I’m not sure that I’ve done correctly - do I need the GPIO.cleanup? will this code work for flashing an LED?)
def lipopi_low_battery_ledblink(channel): global lipopi GPIO.output(low_bat_led_pin, GPIO.HIGH) # led on time.sleep(.5) GPIO.output(low_bat_led_pin, GPIO.LOW) # led off time.sleep(.5)
Added this variable to define the LED pin:
lipopi['low_bat_led_pin'] = 17
Any help with ensuring this will work would be awesome, thanks!