本文整理汇总了Python中PCF8591类的典型用法代码示例。如果您正苦于以下问题:Python PCF8591类的具体用法?Python PCF8591怎么用?Python PCF8591使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PCF8591类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup
def setup():
global CURRENT_DAY
global CURRENT_MON
global CURRENT_HOUR
global CROP
global SYSTEM_CONTROLLER
GPIO.setmode(GPIO.BOARD)
GPIO.setup(RAIN_SENSOR_PIN, GPIO.IN)
ADC.setup(0x48)
global TEMPERATURE_SENSOR
for i in os.listdir('/sys/bus/w1/devices'):
if i != 'w1-bus-master1':
TEMPERATURE_SENSOR = i
print('== Program starting ==')
GPIO.setup(FAN_PIN, GPIO.OUT)
GPIO.setup(ROOF_PIN, GPIO.OUT)
GPIO.setup(HEAT_PIN, GPIO.OUT)
GPIO.setup(WATER_PIN, GPIO.OUT)
GPIO.setup(SHADE_PIN, GPIO.OUT)
GPIO.setup(BLACKOUT_PIN, GPIO.OUT)
GPIO.setup(LIGHT_PIN, GPIO.OUT)
CURRENT_DAY = datetime.datetime.today().day
CURRENT_MON = datetime.datetime.today().month
CURRENT_HOUR = datetime.datetime.today().hour
CROP = Crop('plant.csv')
SYSTEM_CONTROLLER = SystemController(SYSTEM_PINS, GPIO)
# Starting thread for user input
thread.start_new_thread(listen_for_input, ())
示例2: setup
def setup(self):
GPIO.setmode(GPIO.BCM)
ADC.setup(0x48)
LCD.init(0x27, 1)
self.display_text("System startup")
# setup pins for sensors
GPIO.setup(self.THERMISTOR_PIN, GPIO.IN)
GPIO.setup(self.GAS_SENSOR_PIN, GPIO.IN)
GPIO.setup(self.BUZZ_PIN, GPIO.OUT)
GPIO.setup(self.H2O_PIN, GPIO.IN)
# setup pins for "eyes"
# first eye
GPIO.setup(self.SDI_0, GPIO.OUT)
GPIO.setup(self.RCLK_0, GPIO.OUT)
GPIO.setup(self.SRCLK_0, GPIO.OUT)
GPIO.output(self.SDI_0, GPIO.LOW)
GPIO.output(self.RCLK_0, GPIO.LOW)
GPIO.output(self.SRCLK_0, GPIO.LOW)
# second eye
GPIO.setup(self.SDI_1, GPIO.OUT)
GPIO.setup(self.RCLK_1, GPIO.OUT)
GPIO.setup(self.SRCLK_1, GPIO.OUT)
GPIO.output(self.SDI_1, GPIO.LOW)
GPIO.output(self.RCLK_1, GPIO.LOW)
GPIO.output(self.SRCLK_1, GPIO.LOW)
示例3: destroy
def destroy():
ADC.write(0)
Rpwm.stop
Gpwm.stop
Bpwm.stop
GPIO.output(Rpin, GPIO.HIGH)
GPIO.output(Gpin, GPIO.HIGH)
GPIO.output(Bpin, GPIO.HIGH)
GPIO.cleanup
示例4: check_for_gas
def check_for_gas():
status = 1
count = 0
print ADC.read(3)
tmp = GPIO.input(DO);
if tmp != status:
Print(tmp)
else:
Print(0)
示例5: setup
def setup(gpioPort, i2cAddress):
global initialRainIntensityReading
global lowerBoundary
GPIO.setmode(GPIO.BCM)
ADC.setup(i2cAddress)
GPIO.setup(gpioPort, GPIO.IN)
initialRainIntensityReading = ADC.read(0)
# set the delta zone so we dont need to recalc it every time
lowerBoundary = initialRainIntensityReading - rainDelta
print "initial rain intensity reading: ", initialRainIntensityReading
示例6: loop
def loop():
status = 1
while True:
print ADC.read(0)
tmp = GPIO.input(DO);
if tmp != status:
Print(tmp)
status = tmp
time.sleep(0.2)
示例7: setup
def setup():
ADC.setup(0x48)
LCD.init(0x27, 1)
LCD.write(0,0,'System startup...')
time.sleep(1)
ALARM = False
LCD.clear()
GPIO.setup(THERMISTOR_PIN, GPIO.IN)
GPIO.setup(GAS_SENSOR_PIN, GPIO.IN)
GPIO.setup(BUZZ_PIN, GPIO.OUT)
GPIO.setup(H2O_PIN, GPIO.OUT)
GPIO.output(BUZZ_PIN, GPIO.HIGH)
示例8: loop
def loop():
worker = Thread(target=queue_task, args=(q,))
worker.setDaemon(True)
worker.start()
alarm_thread = Thread(target=alarm_task)
alarm_thread.setDaemon(True)
alarm_thread.start()
status = 1
count = 0
q_count = 0
now = datetime.now()
LCD.write(0,0,'System Normal')
while True:
# get and convert temperature
analogTemp = ADC.read(0)
Vr = 5 * float(analogTemp) / 255
Rt = 10000 * Vr / (5 - Vr)
temp = 1/(((math.log(Rt / 10000)) / 3950) + (1 / (273.15 + 25)))
temp = (temp - 273.15) * 9/5 + 32
print 'temperature = ', temp, 'F'
# get and convert gas sensor data
gas = ADC.read(1)
print 'gas sensor = ', gas
# tmp = GPIO.input(GAS_SENSOR)
# if tmp != status:
# check_gas(tmp)
# status = tmp
# if status == 0:
# count += 1
# if count % 2 == 0:
# GPIO.output(BUZZ, 1)
# else:
# GPIO.output(BUZZ, 0)
# else:
# GPIO.output(BUZZ, 1)
# count = 0
# get water data
h2o = ADC.read(2)
print "h2o sensor = " + str(h2o)
update_LCD(temp, gas, h2o)
if q_count > 3.5:
updates = []
updates.append({'type' : 'temperature', 'value': str(temp), 'timestamp': str(datetime.now())})
updates.append({'type' : 'gas', 'value': str(ADC.read(1)), 'timestamp': str(datetime.now())})
updates.append({'type' : 'h2o', 'value': str(h2o), 'timestamp': str(datetime.now())})
q.put(updates)
q_count = 0
q_count = q_count + 1
time.sleep(2)
示例9: loop
def loop():
count = 0
while True:
tmp = ADC.read(0)
if tmp < 50:
count += 1
print "Voice In!! ", count
示例10: loop
def loop():
status = 1
tmp = 1
while True:
analogVal = ADC.read(0)
Vr = 5 * float(analogVal) / 255
Rt = 10000 * Vr / (5 - Vr)
temp = 1/(((math.log(Rt / 10000)) / 3950) + (1 / (273.15+25)))
temp = temp - 273.15
# temp = temp * 9/5 + 32
print 'temperature = ', temp, 'C'
# For a threshold, uncomment one of the code for
# which module you use. DONOT UNCOMMENT BOTH!
#################################################
# 1. For Analog Temperature module(with DO)
#tmp = GPIO.input(DO);
#
# 2. For Thermister module(with sig pin)
if temp > 33:
tmp = 0;
elif temp < 31:
tmp = 1;
#################################################
if tmp != status:
Print(tmp)
status = tmp
time.sleep(0.2)
示例11: loop
def loop():
while True:
tmp = ADC.read(0)
if tmp < 44:
R = 100
G = map(tmp,0, 43, 0, 100)
B = 0
elif tmp < 86:
R = 100-map(tmp, 44, 85, 0, 100)
G = 100
B = 0
elif tmp < 128:
R = 0
G = 100
B = map(tmp, 86, 127, 0, 100)
elif tmp < 170:
R = 0
G = 100-map(tmp, 128, 169, 0, 100)
B = 100
elif tmp < 212:
R = map(tmp, 170, 211, 0, 100)
G = 0
B = 100
elif tmp < 256:
R = 100
G = 0
B = 100-map(tmp, 212, 255, 0, 100)
setColor(R,G,B)
print tmp
示例12: read_illumination
def read_illumination():
global CURRENT_ILLUMINATION
illumination = ADC.read(0)
if (illumination > CURRENT_ILLUMINATION + TOLERANCE_ILLUMINATION or
illumination < CURRENT_ILLUMINATION - TOLERANCE_ILLUMINATION):
CURRENT_ILLUMINATION = illumination
print_line('CURRENT ILLUMINATION: %0.3f' % CURRENT_ILLUMINATION)
return True
return False
示例13: loop
def loop():
count = 0
while True:
voiceValue = ADC.read(0)
if voiceValue:
print 'Value:', voiceValue
if voiceValue < 50:
print "Voice detected! ", count
count += 1
time.sleep(0.2)
示例14: get_temperature_sensor_data
def get_temperature_sensor_data(self):
try:
analogTemp = ADC.read(0)
Vr = 5 * float(analogTemp) / 255
Rt = 10000 * Vr / (5 - Vr)
temp = 1/(((math.log(Rt / 10000)) / 3950) + (1 / (273.15 + 25)))
self.temp = (temp - 273.15) * 9/5 + 32
return self.temp
except:
print "Temp sensor read failed... analog temp = ", analogTemp
示例15: sample
def sample():
currentRainIntensity = ADC.read(0)
data = {}
data['rainReading'] = currentRainIntensity
# if any rain drop is detected
if (lowerBoundary > currentRainIntensity) :
data['rainDetected'] = True;
else:
data['rainDetected'] = False;
return data;