import spidev
from numpy import interp
fromimport time
import datetime
from datetime import sleeptimedelta
# Start SPI connection
spi = spidev.SpiDev() # Created an object
spi.open(0,0)
# Read MCP3008 data
def analogInput(channel, hz):
spi.max_speed_hz = hz
adc = spi.xfer2([1,(8+channel)<<4,0])
data = ((adc[1]&3) << 8) + adc[2]
return data
data_list=list()
init_time = datetime.datetime.now()
while True:
output1 = analogInput(0, 201000000)
output1 = interp(output1, [0, 1023], [0, 100])
print
data_list.append(output1)
if init_time < datetime.datetime.now() - timedelta(seconds=2):
print("min" + str(min(data_list)))
print("max" + str(max(data_list)))
print("avg" + str(sum(data_list)/len(data_list)))
data_list=list()
init_time = datetime.datetime.now()
time.sleep(.5001)
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Mod Moved Comments To Chat