Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Make these LEDs stay on
#1
When I run this in Thonny IDE, the LEDs light up like they are supposed to and the rest of the code works fine. when I run this as a cronjob I get everything except the LEDs. How do I make the LEDs persist until the cron job runs again on the next tenth minute (*/10 * * * *)?
import time
import sys
import requests
from gpiozero import LED
from gpiozero import Button

#Define LED indicators - these are GPIO numbers
LED1 = LED(21) #Blue
LED2 = LED(26) #Red
LED3 = LED(20) #Amber
LED4 = LED(19) #Green
LED5 = LED(16) #Green
LED6 = LED(13) #Green
LED7 = LED(6) #Green
LED8 = LED(12) #Green
LED9 = LED(5) #Pink


EMULATE_HX711=False

reset = Button(18)
#def reset():
#    average = keg1
#    print("Average has been reset to current weight")
    
#reset.when_released = reset

referenceUnit = 1

if not EMULATE_HX711:
    import RPi.GPIO as GPIO
    from hx711 import HX711
else:
    from emulated_hx711 import HX711




hx = HX711(27, 22)
hx.set_reading_format("MSB", "MSB")
hx.set_reference_unit(1)
#hx.reset()
#hx.tare()

        
keg1 = hx.get_weight() + 250000
keg1 = keg1 - 75700
print(keg1)

alert = "Keg1Q " + str(keg1)
base = "autoremotejoaomgcd.appspot.com/sendmessage?key=SecretDeviceIDHiddenForSecurity&message="
alerturl = "https://"+base+alert
r = requests.post(alerturl)

percent = (keg1/502700) * 100
print(percent)
percentT = str(round(percent, 2))
print(percentT)

if 1 >= percent <= 102: #keg is outside of usable range - flashes when keg is missing (indicating tare is complete at startup)
    LED1.blink(.2,.2)
else:
    LED1.off()
   
if 1.1 >= percent >= 5: #Red less than 5% - DANGER
    LED2.blink(.5,.5)
else:
    LED2.off()
               
if 101 >= percent >= 10: #Amber less than 10% - Warning
    LED3.on()
else:
    LED3.off()
               
if 101 >= percent >= 20: #  Green 10-20% - Caution
    LED4.on()
else:
    LED4.off()
               
if 101 >= percent >= 40: #Green2 20-40%
    LED5.on()
else:
    LED5.off()
               
if 101 >= percent >= 60: #Green3 40-60%
    LED6.on()
else:
    LED6.off()
               
if 101 >= percent >= 80: #Green4 60-80%
    LED7.on()
else:
    LED7.off()
               
if 101 >= percent >= 80.1: #Green5 80-100%
    LED8.on()
else:
    LED8.off()
        
hx.power_down()
hx.power_up()
Reply


Messages In This Thread
Make these LEDs stay on - by duckredbeard - Apr-08-2021, 01:01 PM
RE: Make these LEDs stay on - by duckredbeard - Apr-08-2021, 01:33 PM
RE: Make these LEDs stay on - by deanhystad - Apr-08-2021, 05:14 PM
RE: Make these LEDs stay on - by duckredbeard - Apr-08-2021, 09:26 PM
RE: Make these LEDs stay on - by deanhystad - Apr-08-2021, 09:43 PM
RE: Make these LEDs stay on - by duckredbeard - Apr-08-2021, 10:26 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  functional LEDs in an array or list? // RPi user Doczu 5 1,648 Aug-23-2022, 05:37 PM
Last Post: Yoriz
Question How to make a button always stay on a point when resizing the window? _ShevaKadu 5 4,251 Nov-04-2020, 03:59 PM
Last Post: deanhystad
  Orange PI Win steering LEDs connect to GPIO djmcg 0 1,553 Dec-27-2019, 08:26 AM
Last Post: djmcg
  How to iterate over some characters in a string and the others will stay as it is. ? sodmzs 9 4,453 Jun-17-2019, 06:45 PM
Last Post: perfringo
  Absolute newbie asking for help with blinking LEDs misterfrickel 0 2,084 Mar-15-2019, 08:54 AM
Last Post: misterfrickel
  Robot Stay Inside Circular Ring webmanoffesto 4 6,699 Dec-07-2016, 06:57 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020