當前位置: 首頁>>代碼示例>>Python>>正文


Python PCF8591類代碼示例

本文整理匯總了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, ())
開發者ID:hscasn,項目名稱:Greenhouse-Controller-Prototype,代碼行數:35,代碼來源:main.py

示例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)
開發者ID:haloteam,項目名稱:halo,代碼行數:27,代碼來源:Halo.py

示例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
開發者ID:HandcraftCavon,項目名稱:RGBbar,代碼行數:9,代碼來源:RGBbar.py

示例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)
開發者ID:icdeadpll,項目名稱:CIT480DisasterBOT,代碼行數:9,代碼來源:gas_sensor_control.py

示例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
開發者ID:jliamfinnie,項目名稱:iot-disaster,代碼行數:10,代碼來源:rainSensor.py

示例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)
開發者ID:Emilleopold,項目名稱:Sunfounder_37_Sensor_Kit_V2.0_for_RasPi,代碼行數:11,代碼來源:14_rain_detector.py

示例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)
開發者ID:haloteam,項目名稱:halo,代碼行數:12,代碼來源:run.py

示例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)
開發者ID:haloteam,項目名稱:halo,代碼行數:52,代碼來源:run.py

示例9: loop

def loop():
	count = 0
	while True:
		tmp = ADC.read(0)
		if tmp < 50:
			count += 1
			print "Voice In!!  ", count
開發者ID:HandcraftCavon,項目名稱:SSK,代碼行數:7,代碼來源:19_sound_sensor.py

示例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)
開發者ID:haloteam,項目名稱:halo,代碼行數:30,代碼來源:18_thermistor.py

示例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
開發者ID:HandcraftCavon,項目名稱:RGBbar,代碼行數:30,代碼來源:RGBbar.py

示例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
開發者ID:hscasn,項目名稱:Greenhouse-Controller-Prototype,代碼行數:9,代碼來源:main.py

示例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)
開發者ID:Emilleopold,項目名稱:Sunfounder_37_Sensor_Kit_V2.0_for_RasPi,代碼行數:10,代碼來源:19_sound_sensor.py

示例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
開發者ID:haloteam,項目名稱:halo,代碼行數:10,代碼來源:Halo.py

示例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;
開發者ID:jliamfinnie,項目名稱:iot-disaster,代碼行數:11,代碼來源:rainSensor.py


注:本文中的PCF8591類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。