本文整理汇总了Python中PCF8591.read方法的典型用法代码示例。如果您正苦于以下问题:Python PCF8591.read方法的具体用法?Python PCF8591.read怎么用?Python PCF8591.read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PCF8591
的用法示例。
在下文中一共展示了PCF8591.read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_for_gas
# 需要导入模块: import PCF8591 [as 别名]
# 或者: from PCF8591 import read [as 别名]
def check_for_gas():
status = 1
count = 0
print ADC.read(3)
tmp = GPIO.input(DO);
if tmp != status:
Print(tmp)
else:
Print(0)
示例2: loop
# 需要导入模块: import PCF8591 [as 别名]
# 或者: from PCF8591 import read [as 别名]
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)
示例3: loop
# 需要导入模块: import PCF8591 [as 别名]
# 或者: from PCF8591 import read [as 别名]
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)
示例4: loop
# 需要导入模块: import PCF8591 [as 别名]
# 或者: from PCF8591 import read [as 别名]
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)
示例5: loop
# 需要导入模块: import PCF8591 [as 别名]
# 或者: from PCF8591 import read [as 别名]
def loop():
count = 0
while True:
tmp = ADC.read(0)
if tmp < 50:
count += 1
print "Voice In!! ", count
示例6: loop
# 需要导入模块: import PCF8591 [as 别名]
# 或者: from PCF8591 import read [as 别名]
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
示例7: read_illumination
# 需要导入模块: import PCF8591 [as 别名]
# 或者: from PCF8591 import read [as 别名]
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
示例8: get_temperature_sensor_data
# 需要导入模块: import PCF8591 [as 别名]
# 或者: from PCF8591 import read [as 别名]
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
示例9: loop
# 需要导入模块: import PCF8591 [as 别名]
# 或者: from PCF8591 import read [as 别名]
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)
示例10: setup
# 需要导入模块: import PCF8591 [as 别名]
# 或者: from PCF8591 import read [as 别名]
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
示例11: sample
# 需要导入模块: import PCF8591 [as 别名]
# 或者: from PCF8591 import read [as 别名]
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;
示例12: loop
# 需要导入模块: import PCF8591 [as 别名]
# 或者: from PCF8591 import read [as 别名]
def loop():
status = 1
count = 0
while True:
print ADC.read(0)
tmp = GPIO.input(DO);
if tmp != status:
Print(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
time.sleep(0.2)
示例13: loop
# 需要导入模块: import PCF8591 [as 别名]
# 或者: from PCF8591 import read [as 别名]
def loop():
status = 0
while True:
res = ADC.read(0)
print 'Current intensity of magnetic field : ', res
if res - 133 < 5 and res - 133 > -5:
tmp = 0
if res < 128:
tmp = -1
if res > 138:
tmp = 1
if tmp != status:
Print(tmp)
status = tmp
time.sleep(0.2)
开发者ID:Emilleopold,项目名称:Sunfounder_37_Sensor_Kit_V2.0_for_RasPi,代码行数:17,代码来源:17_analog_hall_switch.py
示例14: direction
# 需要导入模块: import PCF8591 [as 别名]
# 或者: from PCF8591 import read [as 别名]
def direction(): #get joystick result
state = ['home', 'up', 'down', 'left', 'right', 'pressed']
i = 0
if ADC.read(0) <= 5:
i = 1 #up
if ADC.read(0) >= 250:
i = 2 #down
if ADC.read(1) >= 250:
i = 3 #left
if ADC.read(1) <= 5:
i = 4 #right
if ADC.read(2) == 0:
i = 5 # Button pressed
if ADC.read(0) - 125 < 15 and ADC.read(0) - 125 > -15 and ADC.read(1) - 125 < 15 and ADC.read(1) - 125 > -15 and ADC.read(2) == 255:
i = 0
return state[i]
示例15: loop
# 需要导入模块: import PCF8591 [as 别名]
# 或者: from PCF8591 import read [as 别名]
def loop():
while True:
humidity1, temperature1 = DHT.read_retry(Sensor, humiture1)
humidity2, temperature2 = DHT.read_retry(Sensor, humiture2)
sound_level = ADC.read(0)
if humidity1 is not None and temperature1 is not None:
import time
ts = time.time()
import datetime
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
print st + ' : T1={0:0.1f}*C H1={1:0.1f}%'.format(temperature1, humidity1) + ' : T2={0:0.1f}*C H2={1:0.1f}%'.format(temperature2, humidity2) + ' : S1=' + format(sound_level)
logging.info(st + ' : T1={0:0.1f}*C H1={1:0.1f}%'.format(temperature1, humidity1) + ' : T2={0:0.1f}*C H2={1:0.1f}%'.format(temperature2, humidity2) + ' : S1=' + format(sound_level))
time.sleep(3600) # delays in seconds (1 hours)
else:
print 'Failed to get reading. Try again!'