Dec-02-2020, 05:03 AM
I just put this together and it seems to be working well. I don't have the LEDs connected yet, but the "print" function proves they will with correct connections. I may add a few more LEDs for the scale between 11 and 13.5, each with a .5 range. I can do that just fine. I'm posting here to see if there are any wasted lines of code, can this be cleaned up?
import time from time import sleep from datetime import datetime import Adafruit_ADS1x15 adc = Adafruit_ADS1x15.ADS1115(address=0x48, busnum=1) from gpiozero import LED GAIN = 2/3 LEDHIGH = LED(21) LEDNORM = LED(26) LEDLOW = LED(16) while 1: value = [0] value[0] = adc.read_adc(0, gain=GAIN) volts = value[0]/32767.0 * 6.144 now = datetime.now() current_time = now.strftime("%H:%M:%S") manifoldraw = volts / .145 manifold = str(round(manifoldraw, 2)) print(current_time, " ", manifold) if 12.25 <= manifoldraw <= 12.75: LEDNORM.on() print("pressure OK") else: LEDNORM.off() #print("off") if 0 <= manifoldraw <=12.24: LEDLOW.on() print("pressure LOW") else: LEDLOW.off() if 12.76 <= manifoldraw <= 99999: LEDHIGH.on() print("pressure HIGH") else: LEDHIGH.off() sleep(1)Basic function in this configuration is that I will have one LED on when the pressure is normal, between 12.25 and 12.75. Other LEDs would indicate when I am higher than 12.76 or lower than 12.24. I intend to add a requests.post that hits a URL that sends a message to my Androids if pressures get above 15 or below 10. Optimum pressure on this application is 12.5. It is for the CO2 manifold for my keg fridge, so pressure is critical to preserve optimum carbonation levels of my homebrew!