• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python wiringpi2.digitalRead函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中wiringpi2.digitalRead函数的典型用法代码示例。如果您正苦于以下问题:Python digitalRead函数的具体用法?Python digitalRead怎么用?Python digitalRead使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了digitalRead函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: measure

def measure():

	wiringpi2.digitalWrite(TRIG, 1)
	time.sleep(0.00001)
	wiringpi2.digitalWrite(TRIG, 0)

	pulse_start = time.time()
	while wiringpi2.digitalRead(ECHO)==0:
		pulse_start = time.time()
	
	# Once a signal is received, the value changes from low (0) to high (1),
	# and the signal will remain high for the duration of the echo pulse.
	# We therefore also need the last high timestamp for ECHO (pulse_end).

	pulse_end = time.time()      
	while wiringpi2.digitalRead(ECHO) == 1:
		pulse_end = time.time()      
	
	# We can now calculate the difference between the two recorded 
	# timestamps, and hence the duration of pulse (pulse_duration).

	pulse_duration = pulse_end - pulse_start
	
	distance = pulse_duration * 17150

	return distance
开发者ID:chuck1,项目名称:rpi-code,代码行数:26,代码来源:sonic.py


示例2: set

  def set(self,newState):
    
    newState = int(newState)

    # FIXME need to catch error
    print "Switching relay " + `self.relayA` + " to " + `newState`

    wiringpi.pinMode(self.relayA,self.OUTPUT_MODE)
    
    initialState = wiringpi.digitalRead(self.relayA)
    wiringpi.digitalWrite(self.relayA, newState)
    currentState = wiringpi.digitalRead(self.relayA)
    
    result = None
    if(initialState == currentState):
    	result = "Target state was already set. No action taken"
    else:
    	result = "Switched"
    
    errors = None
    
    return {
        "controller": self.name,
        "timestamp": datetime.datetime.now().isoformat(' '),
        "result": result,
        "errors": errors,
    }
开发者ID:spikeheap,项目名称:snug-node,代码行数:27,代码来源:RelayController.py


示例3: readData

def readData(pin):
    hum = 0
    temp = 0
    crc = 0
    GPIO.pinMode(pin, 1)
    GPIO.digitalWrite(pin, 1)
    GPIO.digitalWrite(pin, 0)
    GPIO.delay(20)
    GPIO.digitalWrite(pin, 1)
    GPIO.pinMode(pin, 0)
    GPIO.delayMicroseconds(40)
    if GPIO.digitalRead(pin) == 0:
        untilHigh(pin)
        for i in range(16):
            hum <<= 1
            untilLow(pin)
            untilHigh(pin)
            GPIO.delayMicroseconds(28)
            hum += GPIO.digitalRead(pin)
        for i in range(16):
            temp <<= 1
            untilLow(pin)
            untilHigh(pin)
            GPIO.delayMicroseconds(28)
            temp += GPIO.digitalRead(pin)
        for i in range(8):
            crc <<= 1
            untilLow(pin)
            untilHigh(pin)
            GPIO.delayMicroseconds(28)
            crc += GPIO.digitalRead(pin)
        return [True, hum, temp, crc]
    else:
        return [False, hum, temp, crc]
开发者ID:young-mu,项目名称:Wime,代码行数:34,代码来源:dht11.py


示例4: get_distance

    def get_distance(self, sensor):
        #wiringpi.digitalWrite(30,HIGH)
        wiringpi.digitalWrite(sensor.echo, LOW)
        wiringpi.delay(1000)
        wiringpi.digitalWrite(sensor.trigger, HIGH)
        wiringpi.delay(1)
        wiringpi.digitalWrite(sensor.trigger, LOW)
        #start = time.time()
	print "Trying to get distance of sensor " , sensor.position, "Trig: ", sensor.trigger, " Echo:", sensor.echo
	status = LOW
	while(wiringpi.digitalRead(sensor.echo) == LOW):
		status = LOW
	start = time.time()
	while(wiringpi.digitalRead(sensor.echo) == HIGH):
		status = LOW
	end = time.time()	

#	while status == LOW:
#	    feedback = wiringpi.digitalRead(sensor.echo)
#	    if(feedback == HIGH):
#		while(feedback == HIGH):
#		    status = LOW
#		end = time.time()
#		print("Time Elapsed: ", end-start)
#		status = HIGH
#	    if((time.time() - start) > 1):
#		end = time.time()
#		status = HIGH

        # Below divide by 340.29 for air distance, or divide by 1484 for water distance
        return (end - start)*(340.29/2)
开发者ID:Price47,项目名称:JackalopeCapstone,代码行数:31,代码来源:sonar.py


示例5: checkPins

def checkPins():
	global pinStates, holeStates, buffer, escapeFlag
	while True:
		if wiringpi2.digitalRead(shutdownPin) == 0:
			pass
			#sayGoodbyeAndExit(shutdown=True)
		
		for (i, pin) in enumerate(inputPins):
			pinStates[i] = wiringpi2.digitalRead(pin)
			holeStates[i] = holeStates[i] or not pinStates[i]

		if sum(pinStates) == 5:
			if sum(holeStates) > 0 and sum(holeStates) < 5:
				# calculate current input
				value = 0
				for place, digit in enumerate(holeStates):
					value += pow(2, len(holeStates)-place-1) * digit
					
				# decode it and append it to the buffer
				if escapeFlag:
					buffer += str(value)
					escapeFlag = False
				else:
					if value in bonusChars:
						buffer += bonusChars[value]
					elif value == 30:
						escapeFlag = True
					else:
						buffer += chr(value + ord('a') - 1)
					
				# reset hole buffer
			holeStates = [ 0 ] * len(inputPins)
			time.sleep(0.01)
开发者ID:MakeICT,项目名称:binary-punched-card-reader,代码行数:33,代码来源:main.py


示例6: getSwitch

def getSwitch():
    resetSwitch()
    binary = str(1-wpi.digitalRead(switchPin[0])) +\
             str(1-wpi.digitalRead(switchPin[1])) +\
             str(1-wpi.digitalRead(switchPin[2]))
    switch = int(binary, 2)
#    print switch
    return float(switch)
开发者ID:meninosousa,项目名称:NASPi,代码行数:8,代码来源:naspi.py


示例7: updateData

        def updateData(self):
#                print "i value"
                for i in range(len(self.words)):                        
                        if wiringPi.digitalRead(ACK) != 0:
                                wiringPi.digitalWrite(ACK, 0)
                        wiringPi.digitalWrite(CLOCK, 1)

                        self.time1 = time.time()-self.time0
                        while self.time1-self.time2 < CLKSPD:
                                self.time1 = time.time()-self.time0
#                       print round((self.time1-self.time2)*1000,2)

                        wiringPi.digitalWrite(CLOCK, 0)

                        for j in range(len(self.bits)):
                                self.bits[j] = wiringPi.digitalRead(PINS[j])
			"""  
			#dummy data
                        if i == 0:
                                self.bits = [1,1,1,1,1,1,1,1,1,1]
                        elif i == 1:
                                self.bits = [0,0,1,1,0,0,1,0,0,0]
                        elif i == 2:
                                self.bits = [0,0,0,1,1,0,0,1,0,0]
                        elif i == 3:
                                self.bits = [0,1,1,1,1,1,0,1,0,0]
                        elif i == 4:
                                self.bits = [0,0,0,0,1,1,0,0,1,0]
                        elif i == 5:
                                self.bits = [0,0,0,0,0,1,0,1,0,1]
                        elif i == 6:
                                self.bits = [0,0,1,1,0,0,1,0,0,0]
                        elif i == 7:
                                self.bits = [0,0,0,1,1,0,0,1,0,0]
                        elif i == 8:
                                self.bits = [1,1,1,1,1,1,1,1,1,1] # [1,1,1,0,1,0,0,1,1,0]
                        elif i == 9:
                                self.bits = [0,1,0,0,1,1,1,0,0,1]
 			"""
 #                       print i, self.bits
                        
			if (i != 0 and self.bits == [1 for k in range(len(self.bits))]) or (i == 0 and self.bits != [1 for k in range(len(self.bits))]) or i == max(range(len(self.words))):
				wiringPi.digitalWrite(ACK, 1)
			else:
				self.words[i] = list(self.bits)
#			print i, self.words[i]

                        self.time2 = time.time()-self.time0                        
                        while self.time2-self.time1 < CLKSPD:
                                self.time2 = time.time()-self.time0
#                       print round((self.time2-self.time1)*1000,2)

			if (i != 0 and self.bits == [1 for k in range(len(self.bits))]) or (i == 0 and self.bits != [1 for k in range(len(self.bits))]):
				break                        
开发者ID:joerikock,项目名称:Duck-Hunt,代码行数:54,代码来源:gpioHandler.py


示例8: checkButtons

def checkButtons():

    sw1 = not wiringpi.digitalRead(switch_1) # Read switch
    if sw1: print 'switch 1'
    sw2 = not wiringpi.digitalRead(switch_2) # Read switch
    if sw2: print 'switch 2'
    sw3 = not wiringpi.digitalRead(switch_3) # Read switch
    if sw3: print 'switch 3'
    sw4 = not wiringpi.digitalRead(switch_4) # Read switch
    if sw4: print 'switch 4'

    return False
开发者ID:darcyg,项目名称:PiTFT-GPS,代码行数:12,代码来源:PiTFTgps.py


示例9: scanButtons

def scanButtons():
  button = 0x0
  for x in range(0,8):
    if not wiringpi.digitalRead(pin_base+x):
      button = (button | (1 << x))
  LSB = button
  button = 0x0
  for x in range(8,16):
    if not wiringpi.digitalRead(pin_base+x):
      button = (button | (1 << (x-8)))
  MSB = button
  return LSB,MSB
开发者ID:PappaNiklas,项目名称:RaspberryAnt,代码行数:12,代码来源:sender.py


示例10: Poll

	def Poll(self):
		iters = 0
		while not wiringpi.digitalRead(addrPins[self.addr-1]):
			iters += 1
			if iters > 10000: 
				self.isOn = False
				return

		if not wiringpi.digitalRead(dataPins[self.data-1]):	# data is low = segment is lit
			self.isOn = True
		else:
			self.isOn = False
开发者ID:m-kostrzewa,项目名称:PointCloudBoat,代码行数:12,代码来源:depthReader.py


示例11: measure_bit_changes

 def measure_bit_changes(self, maxtime=1.0):
     """Counts the bit flips corisponding to half sycle of the
     water wheel"""
     now = wp.digitalRead(0)
     counter = 0
     t0 = time.time()
     while maxtime > time.time()-t0:
         new = wp.digitalRead(0)
         if now != new:
             counter += 1
             now = new
         time.sleep(0.0001)
     freq = 0.5 * counter / (time.time() - t0)
     return freq
开发者ID:CINF,项目名称:PyExpLabSys,代码行数:14,代码来源:flow_measure.py


示例12: RCTime

    def RCTime(self,pin=11,wiring=True,short=False):
        duration=0
        #not sure if the GPIO version of this translation works,
        #so keep using Wiringpi version
        if wiring==True:
            #initQTI()
            #make pin output
            wp.pinMode(pin,1)
            #set pin to high to discharge capacitor
            wp.digitalWrite(pin,1)
            #wait 1 ms
            time.sleep(0.001)
            #make pin Input
            wp.pinMode(pin,0)
            #turn off internal pullups
            #wp.digitalWrite(pin,0)
            wp.pullUpDnControl(pin,1)
	    #print "here"
            if short == True:
                while wp.digitalRead(pin)==1 and duration < self.rightTail:
                    #wait for the pin to go Low
                    #print pin,    wp.digitalRead(pin)
                    #print 'not yet'
                    duration+=1
            else:
                while wp.digitalRead(pin)==1 and duration <self.cap:
		#           	while wp.digitalRead(pin)==1:
			#print "here"
			duration+=1
            #print duration
	    #wp.pinMode(pin,1)
            #wp.digitalWrite(pin,1)
        else:
            GPIO.setup(pin,GPIO.OUT)
            #set pin to high to discharge capacitor

            GPIO.output(pin,GPIO.LOW)
            #wait 1 ms
            time.sleep(0.1)
            #make pin Input
            GPIO.setup(pin,GPIO.IN)
            #GPIO.setup(pin,GPIO.IN,GPIO.PUD_DOWN)
            #turn off internal pullups
            while GPIO.input(pin)== GPIO.LOW:
                #wait for the pin to go Low
                #print GPIO.input(sensorIn)
                duration+=1
	#print duration, pin
        return duration
开发者ID:Riuchando,项目名称:sumorobot,代码行数:49,代码来源:qtilClass.py


示例13: WaitDRDY

    def WaitDRDY(self):
        """
        Delays until DRDY line goes low, allowing for automatic calibration
        """
        start = time.time()
        elapsed = time.time() - start

        # Waits for DRDY to go to zero or TIMEOUT seconds to pass
        drdy_level = wp.digitalRead(self.DRDY_PIN)
        while (drdy_level == wp.HIGH) and (elapsed < self.DRDY_TIMEOUT):
            elapsed = time.time() - start
            drdy_level = wp.digitalRead(self.DRDY_PIN)

        if elapsed >= self.DRDY_TIMEOUT:
            print("WaitDRDY() Timeout\r\n")
开发者ID:heathsd,项目名称:PyADS1256,代码行数:15,代码来源:pyads1256.py


示例14: main_loop

def main_loop():
  global current
  display_main_screen()
  while 1:
    key = wiringpi.digitalRead(BUTTON_OK)
    fkey = wiringpi.digitalRead(BUTTON_FKEY)
    if key == 1:
      #photo.take_sync_photo(comm_server, lcd)
      actions.run_command(current, comm_server, lcd)
      display_main_screen()
    if fkey == 1:
      print('fkey')
      current=(current+1)%actions.get_count()
      display_main_screen()
    time.sleep(0.2)
开发者ID:marcingorecki,项目名称:RPiCam,代码行数:15,代码来源:server.py


示例15: read

 def read(self, toread):
     if toread == 'switch':
         if (tm.time() - self.timeread[0]) > 0.01:
             self.timeread[0] = tm.time()
             self.switch = int(wpi.digitalRead(self.pin_b))
         return self.switch
     if toread == 'pushbutton':
         if (tm.time() - self.timeread[1]) > 0.01:
             self.timeread[1] = tm.time()
             self.pushbutton = int(wpi.digitalRead(self.pin_p))
         return self.pushbutton
     if toread == 'valve':
         if (tm.time() - self.timeread[2]) > 0.01:
             self.timeread[2] = tm.time()
             self.valve = int(wpi.digitalRead(self.pin_r))
         return self.valve
开发者ID:giuliogrechi,项目名称:pirriga,代码行数:16,代码来源:valve.py


示例16: button_raw_press

def button_raw_press():
    # simple debounce with busy-waiting
    time.sleep(DEBOUNCE_MS // 1000)
    if not wiringpi2.digitalRead(BUTTON_PIN):
        global count
        count += 1
        print("BUTTON PRESS: %d" % (count))
开发者ID:nalajcie,项目名称:gPhotoBooth,代码行数:7,代码来源:dimming_button_wiring.py


示例17: action

def action(changePin, action):
   # Convert the pin from the URL into an integer:
   changePin = int(changePin)
   # Get the device name for the pin being changed:
   deviceName = pins[changePin]['name']
   # If the action part of the URL is "on," execute the code indented below:
   if action == "on":
      # Set the pin low:
      wiringpi.digitalWrite(changePin, 0)
      # Save the status message to be passed into the template:
      #message = "Turned " + deviceName + "on."
   if action == "off":
      wiringpi.digitalWrite(changePin, 1)
      #message = "Turned " + deviceName + " off."
   if action == "toggle":
      # Read the pin and set it to whatever it isn't (that is, toggle it):
      wiringpi.digitalWrite(changePin, not wiringpi.digitalWrite(changePin))
      #message = "Toggled " + deviceName + "."

   # For each pin, read the pin state and store it in the pins dictionary:
   for pin in pins:
      pins[pin]['state'] = wiringpi.digitalRead(pin)

   # Along with the pin dictionary, put the message into the template data dictionary:
   templateData = {
   #   'message' : message,
      'pins' : pins
   }

   return render_template('main.html', **templateData)
开发者ID:brycethomsen,项目名称:xmaspi,代码行数:30,代码来源:xmasweb.py


示例18: handle

    def handle(self):
        received_data = self.request[0].strip()
        data = "test"
        socket = self.request[1]

        if received_data == "read":
            print "read_all"
            data = ''
            for i in range(0, 20):
                data += str(wp.digitalRead(i))

        for i in range(0, 9):
            if (received_data[0:11] == "set_state_" + str(i + 1)):
                val = received_data[11:].strip()
                if val == '0':
                    wp.digitalWrite(i, 0)
                    data = "ok"
                if val == '1':
                    wp.digitalWrite(i, 1)
                    data = "ok"

        for i in range(9, 20):
            if (received_data[0:12] == "set_state_" + str(i + 1)):
                val = received_data[12:].strip()
                if val == '0':
                    wp.digitalWrite(i, 0)
                    data = "ok"
                if val == '1':
                    wp.digitalWrite(i, 1)
                    data = "ok"

        socket.sendto(data, self.client_address)
开发者ID:JNRiedel,项目名称:PyExpLabSys,代码行数:32,代码来源:socket_server.py


示例19: get_status

    def get_status(self, port_name):
        pin = self.PINS[port_name]
        if pin is None:
            self.log.error('Provided port "%s" not found.', port_name)
            return -1

        return wiringpi2.digitalRead(pin)
开发者ID:DK2007,项目名称:TgBStoneSodaBot,代码行数:7,代码来源:gpiopins.py


示例20: Update

	def Update(self):
		data = wiringpi.digitalRead(self.pin)
		if data:
#			print self.pin

			if not self.isMidPulse:
				self.isMidPulse = True
				self.lastPulseStart = wiringpi.micros()

		if not data:
			if self.isMidPulse:
				self.isMidPulse = False
				pulseEnd = wiringpi.micros()

				thisPulseLen = pulseEnd - self.lastPulseStart
				self.pulses.append(thisPulseLen)
				numElements = len(self.pulses)
				if numElements > numSamplesForAvg: self.pulses.pop(0) # remove oldest sample if have enough
				averagedPulseLen = 0
				for el in self.pulses: averagedPulseLen += el
				averagedPulseLen /= numElements

				self.currentAvgLen = averagedPulseLen

				if self.isPrintData and numElements >= numSamplesForAvg:
					currTime = time.time()
					if currTime - self.lastOutput > outputPeriod or self.lastOutput == 0.0:
						self.lastOutput = time.time()
						procComms.PrintData(self.name + ', ' + str(self.InPercent()))
开发者ID:m-kostrzewa,项目名称:PointCloudBoat,代码行数:29,代码来源:radioReceiver.py



注:本文中的wiringpi2.digitalRead函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python wiringpi2.digitalWrite函数代码示例发布时间:2022-05-26
下一篇:
Python wiringpi2.delay函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap