import mcp3008

m = mcp3008.read_pct(0)

print("Maisture level: {:>5}".format(m))
Esempio n. 2
0
PREVIOUS_LINE="\x1b[1F"
RED_BACK="\x1b[41;37m"
GREEN_BACK="\x1b[42;30m"
YELLOW_BACK="\x1b[43;30m"
RESET="\x1b[0m"
readings = []

delta = datetime.timedelta(minutes=10)
next_time = datetime.datetime.now()+delta
next_water = datetime.datetime.now()

#the main sensor reading and plotting loop
while True:
    dt = datetime.datetime.now()
    while dt < next_time:
       n = mcp3008.read_pct(5)
       if n>15 and n<85:
		if len(readings) >= 1000:
            		del readings[0];
       		readings.append(n)
       dt = datetime.datetime.now();
    else:
        # Take the average from the readings list to smooth the graph a little
        m = round(((sum(readings)/float(len(readings)))),1)             
        readings = []
        # write the data to plotly
        stream.write({'x': datetime.datetime.now(), 'y': m})
        if m < 25:
    		background = RED_BACK
	elif m < 65:
    		background = YELLOW_BACK
Esempio n. 3
0
PREVIOUS_LINE="\x1b[1F"
RED_BACK="\x1b[41;37m"
GREEN_BACK="\x1b[42;30m"
YELLOW_BACK="\x1b[43;30m"
RESET="\x1b[0m"
readings = []

delta = datetime.timedelta(minutes=10)
next_time = datetime.datetime.now()+delta
next_water = datetime.datetime.now()

#the main sensor reading and plotting loop
while True:
    dt = datetime.datetime.now()
    while dt < next_time:
       n = 100-mcp3008.read_pct(5)
       if n>15 and n<85:
		if len(readings) >= 1000:
            		del readings[0];
       		readings.append(n)
       dt = datetime.datetime.now();
    else:
        # Take the average from the readings list to smooth the graph a little
        m = round(1.5*((sum(readings)/float(len(readings)))),1)             
        readings = []
        # write the data to plotly
        stream.write({'x': datetime.datetime.now(), 'y': m})
        if m < 25:
    		background = RED_BACK
	elif m < 65:
    		background = YELLOW_BACK