当前位置: 首页>>代码示例>>Python>>正文


Python machine.Pin类代码示例

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


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

示例1: __init__

    def __init__(self, debug=False, baud=100000):
        # From datasheet
        # Bit rate – up to 12 MHz1
        # ▪ Polarity – CPOL = 1; clock transition high-to-low on the leading edge and low-to-high on the
        #   trailing edge
        # ▪ Phase – CPHA = 1; setup on the leading edge and sample on the trailing edge
        # ▪ Bit order – MSB first
        # ▪ Chip select polarity – active low
        self.spi = SPI(0)
        try:
            self.spi.init(mode=SPI.MASTER, baudrate=baud, bits=8,
                          polarity=1, phase=1, firstbit=SPI.MSB,
                          pins=('GP31', 'GP16', 'GP30')) # CLK, MOSI, MISO
        except AttributeError:
            self.spi.init(baudrate=baud, bits=8,
                          polarity=1, phase=1, firstbit=SPI.MSB,
                          pins=('GP31', 'GP16', 'GP30')) # CLK, MOSI, MISO

        # These are all active low!
        self.tc_en_bar = Pin('GP4', mode=Pin.OUT)

        self.disable()

        self.tc_busy_bar = Pin('GP5', mode=Pin.IN)
        self.tc_busy_bar.irq(trigger=Pin.IRQ_RISING) # Wake up when it changes
        self.tc_cs_bar = Pin('GP17', mode=Pin.ALT, alt=7)

        self.debug = debug
开发者ID:widget,项目名称:iot-display,代码行数:28,代码来源:epd.py

示例2: __init__

  def __init__(self, pinNr, activeLow, externalResistor=False):
    if externalResistor:
      self._pin = Pin(pinNr, Pin.IN) 
    else:
      self._pin = Pin(pinNr, Pin.IN, Pin.PULL_UP if activeLow else Pin.PULL_DOWN) 

    # number of millisec that have to pass by before a click is detected.
    self._clickTicks = 200

    # number of millisec that have to pass by before a long button press is detected.
    self._pressTicks = 1000

    self._debounceTicks = 50 # number of ticks for debounce times.
 
    # starting with state 0: waiting for button to be pressed
    self._state = 0
    self._isLongPressed = False # Keep track of long press state

    if (activeLow):
      # button connects ground to the pin when pressed.
      self._buttonReleased = 1  # notPressed
      self._buttonPressed = 0
    else:
      # button connects VCC to the pin when pressed.
      self._buttonReleased = 0
      self._buttonPressed = 1


    self._clickFunc = None
    self._doubleClickFunc = None
    self._longPressStartFunc = None
    self._longPressStopFunc = None
    self._duringLongPressFunc = None

    self._startTime = None
开发者ID:tgfuellner,项目名称:OneButton,代码行数:35,代码来源:OneButton.py

示例3: activate

def activate(state):
    global inPin
    if(state):
        inPin = Pin(12, Pin.IN, Pin.PULL_UP)
        inPin.irq(trigger=Pin.IRQ_RISING, handler=timeUS)
    # Disables the internal pull-up, therefore preventing any further RISING_EDGE case.
    else:
        inPin = Pin(12, Pin.IN)
开发者ID:DanijelMi,项目名称:Micropython_MQTT_8266bulb,代码行数:8,代码来源:triac.py

示例4: isLight

def isLight(dataPin):
    """ Check if it's light or dark, using a CEG013600 ambient light sensor connected to the GPIO pin named by dataPin """
    light_in = Pin(dataPin, mode=Pin.IN)
    if light_in.value() == 1:
        """ 1 means dark """
        return False
    else:
        return True
开发者ID:Ortofta,项目名称:wipy,代码行数:8,代码来源:light.py

示例5: __init__

    def __init__(self, pin_1, pin_2, pwm_pin):
        self.pin_1 = Pin(pin_1, mode=Pin.OUT, pull=None)
        self.pin_1.value(0)

        self.pin_2 = Pin(pin_2, mode=Pin.OUT, pull=None)
        self.pin_1.value(0)

        self.pwm = TB6612FNG_channel._pwm.channel(self.id(), pin=pwm_pin, duty_cycle=1)
        self.pwm.duty_cycle(0)
开发者ID:H-LK,项目名称:pycom-libraries,代码行数:9,代码来源:TB6612FNG.py

示例6: near

 def near(self): 
     id = int(str(self)[4:-1]) #unsafe!
     pin15=Pin(15,Pin.OUT)
     pin15.value(1)
     adc=ADC(Pin(id))
     adc.atten(ADC.ATTN_11DB)
     approximate =adc.read()
     pin15.value(0)
     return approximate
开发者ID:radiumray,项目名称:mdxly,代码行数:9,代码来源:mixgo.py

示例7: __init__

	def __init__(self, latch, clock, data):
		self._latch = latch
		self._clock = clock
		self._data = data
		self._latchPin = Pin(latch, mode=Pin.OUT)
		self._latchPin.value(0)
		self._clockPin = Pin(clock, mode=Pin.OUT)
		self._clockPin.value(1)
		self._dataPin = Pin(data, mode=Pin.OUT)
		self._dataPin.value(0)
开发者ID:cubeberg,项目名称:Wipy595ShiftRegister,代码行数:10,代码来源:ShiftReg.py

示例8: TB6612FNG

class TB6612FNG(object):

    def __init__(self, a_1, a_2, a_pwm, b_1, b_2, b_pwm, standby_pin):
        self._standby = Pin(standby_pin, mode=Pin.OUT, pull=None)
        self._standby.value(1)
        self.channelA = _TB6612FNG_channel(a_1, a_2, a_pwm)
        self.channelB = _TB6612FNG_channel(b_1, b_2, b_pwm)

    def standby(self, *args):
        return self._standby.value(*args)
开发者ID:H-LK,项目名称:pycom-libraries,代码行数:10,代码来源:TB6612FNG.py

示例9: __init__

    def __init__(self):
        #        OUTPUT/INPUT
        self.pins = ['GP16', 'GP13']
        self.outputPin = Pin(self.pins[0], mode=Pin.OUT, value=1)
        self.inputPin = Pin(self.pins[1], mode=Pin.IN, pull=Pin.PULL_UP)

        self.triggerCount = 0
        self._triggerType_ = Pin.IRQ_RISING
        self.inputIRQ = self.inputPin.irq(trigger=self._triggerType_, handler=self.pinHandler)
        self.irqState = True
开发者ID:bhclowers,项目名称:WIPYDAQ,代码行数:10,代码来源:wipyDAQ_v1pt6.py

示例10: test

def test():
    stx = Pin(Pin.board.Y5, Pin.OUT_PP)         # Define pins
    sckout = Pin(Pin.board.Y6, Pin.OUT_PP)
    sckout.value(0) # Don't assert clock until data is set
    srx = Pin(Pin.board.Y7, Pin.IN)
    sckin = Pin(Pin.board.Y8, Pin.IN)

    objsched = Sched(heartbeat = 1)
    with SynCom(objsched, False, sckin, sckout, srx, stx) as channel:
        objsched.add_thread(initiator_thread(channel))
        objsched.run()
开发者ID:Usagimimi,项目名称:Micropython-scheduler,代码行数:11,代码来源:sr_init.py

示例11: __init__

class Relay:

    def __init__(self, pin, initialValue=0):
        self.controlPin = Pin(pin, Pin.OUT)
        self.Open()
        pass
    
    def Open(self):
        self.controlPin.value(0)
        
    def Close(self):
        self.controlPin.value(1)
开发者ID:borigas,项目名称:GarageMqtt,代码行数:12,代码来源:Relay.py

示例12: __init__

    def __init__(self):
        self.x_adc = ADC(1)

        self.btn_speed_up = Pin("P13", mode=Pin.IN, pull=Pin.PULL_UP)
        self.btn_speed_down = Pin("P15", mode=Pin.IN, pull=Pin.PULL_UP)
        self.btn_speed_full = Pin("P14", mode=Pin.IN, pull=Pin.PULL_UP)
        self.btn_speed_off = Pin("P16", mode=Pin.IN, pull=Pin.PULL_UP)

        self.x_mid = 0
        
        self.calibrate()
        self.connect()
        self.loop()
开发者ID:DanielO,项目名称:micropython,代码行数:13,代码来源:powerup.py

示例13: main

def main(use_stream=False):
	s = socket.socket()

	# Binding to all interfaces - server will be accessible to other hosts!
	ai = socket.getaddrinfo("0.0.0.0", 8080)
	print("Bind address info:", ai)
	addr = ai[0][-1]

	#prepping LED pin
	p = Pin(2,Pin.OUT)
#	p.high()
#	time.sleep(1)
#	p.low()


	s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
	s.bind(addr)
	s.listen(5)
	print("Listening, connect your browser to http://<this_host>:8080/")

	counter = 0
	while True:
		res = s.accept()
		client_s = res[0]
		client_addr = res[1]
		print("Client address:", client_addr)
		print("Client socket:", client_s)
		print("Request:")
		if use_stream:
			# MicroPython socket objects support stream (aka file) interface
			# directly.
			#print(client_s.read(4096))
			val = client_s.read(4096)
			print(val)
			client_s.write(CONTENT % counter)
		else:
			#print(client_s.recv(4096))
			val = client_s.recv(4096)
			print(val)
			client_s.send(CONTENT % counter)
		if "GET /toggle" in val:
			print("Toggling!")
			p.high()
			time.sleep(1)
			p.low()
			machine.reset()
		client_s.close()
		counter += 1
		print()
开发者ID:Narcolapser,项目名称:automatic-fiesta,代码行数:49,代码来源:Glucose-Garagedoor.py

示例14: __init__

class LaserBeam:
    def __init__(self, laser_pinname, photodiode_pinname):
        self.laser = Pin(laser_pinname, Pin.OUT_OD)
        self.photodiode = ADC(photodiode_pinname)
        self.threshold = 100

    def ping(self):
        dark = self.photodiode.read()
        self.laser.value(0)          # pull down to on
        light = self.photodiode.read()
        self.laser.value(1)          # float to off
        return light-dark

    def interrupted(self):
        return self.ping() < self.threshold \
            and sum(self.ping() for i in range(10)) < 10 * self.threshold
开发者ID:pramasoul,项目名称:pyboard-music-detector,代码行数:16,代码来源:bug.py

示例15: __init__

	def __init__(self, triggerGPIO, echoGPIO):
		self.triggerPin = Pin(triggerGPIO, mode = Pin.OUT)
		self.echoPin = Pin(echoGPIO, mode = Pin.IN)
		# The var to know if we have 28 or 028 in the decimal part
		self.mm_decimal = ""
		# Distance initated to -1 while nothing
		self.mm = -1
		self.cm = -1
开发者ID:gabriel-farache,项目名称:homautomation,代码行数:8,代码来源:HC-SR04.py


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