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


Python pyb.Pin类代码示例

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


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

示例1: __init__

	def __init__(self):
		
		# set up motor with PWM and timer control
		self.A1 = Pin('X3',Pin.OUT_PP)	# A is right motor
		self.A2 = Pin('X4',Pin.OUT_PP)
		self.B1 = Pin('X7',Pin.OUT_PP)	# B is left motor
		self.B2 = Pin('X8',Pin.OUT_PP)
		self.PWMA = Pin('X1')			
		self.PWMB = Pin('X2')
		self.speed = 0		# +100 full speed forward, -100 full speed back
		self.turn = 0		# turn is +/-100; 0 = left/right same speed, 
							# ... +50 = left at speed, right stop, +100 = right back full
		# Configure counter 2 to produce 1kHz clock signal
		self.tim = Timer(2, freq = 1000)
		# Configure timer to provide PWM signal
		self.motorA = self.tim.channel(1, Timer.PWM, pin = self.PWMA)
		self.motorB = self.tim.channel(2, Timer.PWM, pin = self.PWMB)
		self.lsf = 0		# left motor speed factor +/- 1
		self.rsf = 0		# right motor speed factor +/- 1
		self.countA = 0			# speed pulse count for motorA
		self.countB = 0			# speed pulse count for motorB
		self.speedA = 0			# actual speed of motorA
		self.speedB = 0			# actual speed of motorB
		
		# Create external interrupts for motorA and motorB Hall Effect Senors
		self.motorA_int = pyb.ExtInt ('Y4', pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_NONE,self.isr_motorA)
		self.motorB_int = pyb.ExtInt ('Y6', pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_NONE,self.isr_motorB)
		self.speed_timer = pyb.Timer(8, freq=10)
		self.speed_timer.callback(self.isr_speed_timer)
开发者ID:Kurtizl,项目名称:Balancing-Robot,代码行数:29,代码来源:motor.py

示例2: __init__

class TrackBall:
    def __init__(self,qq):
        self.volEnQueueable  = EnQueueable((EnQueueable.INC,EnQueueable.VOL),qq)
        self.toneEnQueueable = EnQueueable((EnQueueable.INC,EnQueueable.TONE),qq)
        self.targCoilID = 0;
        self.x1=Pin(State.trackballStateDict['x1'], Pin.IN, Pin.PULL_DOWN)
        self.x2=Pin(State.trackballStateDict['x2'], Pin.IN, Pin.PULL_DOWN)
        self.y1=Pin(State.trackballStateDict['y1'], Pin.IN, Pin.PULL_DOWN)
        self.y2=Pin(State.trackballStateDict['y2'], Pin.IN, Pin.PULL_DOWN)
        self.extInts = (ExtInt(State.trackballStateDict['x1'],
                                   ExtInt.IRQ_RISING,
                                   Pin.PULL_DOWN,
                                   self.x11),
                        ExtInt(State.trackballStateDict['y1'],
                                   ExtInt.IRQ_RISING,
                                   Pin.PULL_DOWN,
                                   self.y11))
            
    def x11(self,unused):
        if self.x2.value():
            self.volEnQueueable.push(self.targCoilID,-1)
        else:
            self.volEnQueueable.push(self.targCoilID,1)

    def y11(self,unused):
        if self.y2.value():
            self.toneEnQueueable.push(self.targCoilID,-1)
        else:
            self.toneEnQueueable.push(self.targCoilID,1)
开发者ID:gratefulfrog,项目名称:ArduGuitar,代码行数:29,代码来源:trackball.py

示例3: start

    def start(self, speed, direction):
        PWM_py_pin = Pin(self.PWMpin)
        DIR_py_pin = Pin(self.DIRpin, Pin.OUT_PP)

        tim = Timer(self.timer_id, freq=1000)
        ch = tim.channel(self.channel_id, Timer.PWM, pin=PWM_py_pin)

        if direction in ('cw', 'CW', 'clockwise'):
            DIR_py_pin.high()

        elif direction in ('ccw', 'CCW', 'counterclockwise'):
            DIR_py_pin.low()

        else:
            raise ValueError('Please enter CW or CCW')

        if 0 <= speed <= 100:
            ch.pulse_width_percent(speed)

        else:
            raise ValueError("Please enter a speed between 0 and 100")

        self.isRunning        = True
        self.currentDirection = direction
        self.currentSpeed     = speed
开发者ID:CRAWlab,项目名称:ARLISS,代码行数:25,代码来源:motor_class.py

示例4: Relay

class Relay(object):
  """Control a relay board with an output pin.  Set on to True to drive the relay pin low
     which turns the relay on."""

  def __init__( self, pin ) :
    """Pin may be a pin name or pyb.Pin object set for output."""

    if type(pin) == str:
      self._pin = Pin(pin, Pin.OUT_PP, Pin.PULL_DOWN)
    elif type(pin) == Pin:
      self._pin = pin
    else:
      raise Exception("pin must be pin name or pyb.Pin")

    self.on = False

  @property
  def on( self ) : return self._pin.value()

  @on.setter
  def on( self, value ) :
    if value:
      self._pin.low()
    else:
      self._pin.high()
开发者ID:rolandvs,项目名称:GuyCarverMicroPythonCode,代码行数:25,代码来源:Relay.py

示例5: __init__

class STAccel:
    def __init__(self):
        self.cs_pin = Pin('PE3', Pin.OUT_PP, Pin.PULL_NONE)
        self.cs_pin.high()
        self.spi = SPI(1, SPI.MASTER, baudrate=328125, polarity=0, phase=1, bits=8)

        self.who_am_i = self.read_id()

        if self.who_am_i == LIS302DL_WHO_AM_I_VAL:
            self.write_bytes(LIS302DL_CTRL_REG1_ADDR, bytearray([LIS302DL_CONF]))
            self.sensitivity = 18
        elif self.who_am_i == LIS3DSH_WHO_AM_I_VAL:
            self.write_bytes(LIS3DSH_CTRL_REG4_ADDR, bytearray([LIS3DSH_CTRL_REG4_CONF]))
            self.write_bytes(LIS3DSH_CTRL_REG5_ADDR, bytearray([LIS3DSH_CTRL_REG5_CONF]))
            self.sensitivity = 0.06 * 256
        else:
            raise Exception('LIS302DL or LIS3DSH accelerometer not present')

    def convert_raw_to_g(self, x):
        if x & 0x80:
            x = x - 256
        return x * self.sensitivity / 1000

    def read_bytes(self, addr, nbytes):
        if nbytes > 1:
            addr |= READWRITE_CMD | MULTIPLEBYTE_CMD
        else:
            addr |= READWRITE_CMD
        self.cs_pin.low()
        self.spi.send(addr)
        #buf = self.spi.send_recv(bytearray(nbytes * [0])) # read data, MSB first
        buf = self.spi.recv(nbytes)
        self.cs_pin.high()
        return buf

    def write_bytes(self, addr, buf):
        if len(buf) > 1:
            addr |= MULTIPLEBYTE_CMD
        self.cs_pin.low()
        self.spi.send(addr)
        for b in buf:
            self.spi.send(b)
        self.cs_pin.high()

    def read_id(self):
        return self.read_bytes(WHO_AM_I_ADDR, 1)[0]

    def x(self):
        return self.convert_raw_to_g(self.read_bytes(OUT_X_ADDR, 1)[0])

    def y(self):
        return self.convert_raw_to_g(self.read_bytes(OUT_Y_ADDR, 1)[0])

    def z(self):
        return self.convert_raw_to_g(self.read_bytes(OUT_Z_ADDR, 1)[0])

    def xyz(self):
        return (self.x(), self.y(), self.z())
开发者ID:Achimh3011,项目名称:micropython,代码行数:58,代码来源:staccel.py

示例6: __init__

 def __init__( self, forward, backward, speed ) :
   """forward pin name, backward pin name, speed = (pin name, timer#)
      Need to make sure the given timer # is associated with the speed
      pin or an exception will be raised.  The speed pin must support
      PWM."""
   self._forward = Pin(forward, Pin.OUT_PP)
   self._backward = Pin(backward, Pin.OUT_PP)
   self._speedControl = PWM(speed[0], speed[1])
   self._speed = 0
开发者ID:rolandvs,项目名称:GuyCarverMicroPythonCode,代码行数:9,代码来源:L298N.py

示例7: check_joystick

def check_joystick():

	adc_1 = ADC(Pin('X19'))
	adc_2 = ADC(Pin('X20'))
	J_sw = Pin('Y11', Pin.IN)

	while True:
		print('Vertical: ',adc_1.read(), 'Horizontal: ', adc_2.read(), 'Switch: ',J_sw.value())
		pyb.delay(2000)	
开发者ID:old-blighty,项目名称:de1-electonics-group-project,代码行数:9,代码来源:full.py

示例8: declare_channel

 def declare_channel(self, channel, direction):
     try:
         self.available_pins.index(channel)
         if self._find_channel(channel):
             return ;
         pin = Pin(channel)
         if direction:
             pin.init(Pin.OUT_PP)
         else:
             pin.init(Pin.IN, Pin.PULL_UP)
         self.channels += [pin]
     except:
         pass
开发者ID:SolitonNew,项目名称:pyhome,代码行数:13,代码来源:drivers.py

示例9: __init__

 def __init__(self,qq):
     self.x1=Pin('Y9', Pin.IN, Pin.PULL_DOWN)
     self.x2=Pin('Y7', Pin.IN, Pin.PULL_DOWN)
     self.y1=Pin('Y10', Pin.IN, Pin.PULL_DOWN)
     self.y2=Pin('Y8', Pin.IN, Pin.PULL_DOWN)
     self.extInts = (ExtInt('Y9',
                            ExtInt.IRQ_RISING,
                            Pin.PULL_DOWN,
                            self.x11),
                     ExtInt('Y10',
                            ExtInt.IRQ_RISING,
                            Pin.PULL_DOWN,
                            self.y11))
开发者ID:gratefulfrog,项目名称:ArduGuitar,代码行数:13,代码来源:trackballTest.py

示例10: ultrasound

def	ultrasound():
	
	Trigger = Pin('X3', Pin.OUT_PP)
	Echo = Pin('X4',Pin.IN)
	
	# Create a microseconds counter.
	micros = pyb.Timer(2, prescaler=83, period=0x3fffffff)
	micros.counter(0)
	start = 0
	end = 0
	
	# Send a 20usec pulse every 10ms
	while True:
		Trigger.high()
		pyb.udelay(20)
		Trigger.low()
		
		# Wait until pulse starts
		while Echo.value() == 0:   # do nothing
			start = micros.counter()	# mark time at rising edge
		
		# Wait until pulse goes low
		while Echo.value() == 1:   # do nothing
			end = micros.counter()		# mark time at falling edge
		
		# Duration echo pulse = end - start
		# Divide this by 2 to take account of round-trip
		# Speed of sound in air is 340 m/s or 29 us/cm
		# Distance in cm = (pulse_width)*0.5/29
		distance = int(((end - start) / 2) / 29)
		print('Distance: ', distance, ' cm')
		pyb.delay(500)
开发者ID:old-blighty,项目名称:de1-electonics-group-project,代码行数:32,代码来源:full.py

示例11: flash_LEDs

def	flash_LEDs():

	rLED = Pin('Y9', Pin.OUT_PP)
	bLED = Pin('Y10',Pin.OUT_PP)

	while True:
		rLED.high()
		pyb.delay(250)
		bLED.high()
		pyb.delay(250)
		rLED.low()
		pyb.delay(250)
		bLED.low()
		pyb.delay(250)
开发者ID:old-blighty,项目名称:de1-electonics-group-project,代码行数:14,代码来源:full.py

示例12: __init__

class TrackBall:
    def __init__(self,qq):
        self.volEnQueueable  = EnQueueable((EnQueueable.INC,EnQueueable.VOL),qq)
        self.toneEnQueueable = EnQueueable((EnQueueable.INC,EnQueueable.TONE),qq)
        self.targCoilID = 0;
        self.x1=Pin(State.trackballStateDict['x1'], Pin.IN, Pin.PULL_DOWN)
        self.x2=Pin(State.trackballStateDict['x2'], Pin.IN, Pin.PULL_DOWN)
        self.y1=Pin(State.trackballStateDict['y1'], Pin.IN, Pin.PULL_DOWN)
        self.y2=Pin(State.trackballStateDict['y2'], Pin.IN, Pin.PULL_DOWN)
        self.extInts = (ExtInt(State.trackballStateDict['x1'],
                                   ExtInt.IRQ_RISING,
                                   Pin.PULL_DOWN,
                                   self.x11),
                        ExtInt(State.trackballStateDict['y1'],
                                   ExtInt.IRQ_RISING,
                                   Pin.PULL_DOWN,
                                   self.y11))
            
    def x11(self,unused):
        if self.x2.value():
            irq_state = disable_irq()
            self.volEnQueueable.push(self.targCoilID,-1)
            enable_irq(irq_state)
        else:
            irq_state = disable_irq()
            self.volEnQueueable.push(self.targCoilID,1)
            enable_irq(irq_state)
    def y11(self,unused):
        if self.y2.value():
            irq_state = disable_irq()
            self.toneEnQueueable.push(self.targCoilID,-1)
            enable_irq(irq_state)
        else:
            irq_state = disable_irq()
            self.toneEnQueueable.push(self.targCoilID,1)
            enable_irq(irq_state)

    def __repr__(self):
        res = 'TrackBall:'                                        + \
              '\nvolEnQueueable: \t' + repr(self.volEnQueueable)  + \
              '\ntoneEnQueueable:\t' + repr(self.toneEnQueueable) + \
              '\ntargCoilID:     \t' + str(self.targCoilID)       + \
              '\nx1:             \t' + str(self.x1)               + \
              '\nx2:             \t' + str(self.x2)               + \
              '\ny1:             \t' + str(self.y1)               + \
              '\ny2:             \t' + str(self.y2)               #+ \
              #'\nExtInts:        \t' + str([i for i in self.extInts])
        return res
开发者ID:gratefulfrog,项目名称:ArduGuitar,代码行数:48,代码来源:hardware.py

示例13: __init__

 def __init__(self, bus=1, baudrate=328125, polarity=0, phase=0, ss='A4'):
     self.ss = Pin(ss, Pin.OUT)
     self.ss.high()
     self.spi = SPI(bus, SPI.MASTER, baudrate=baudrate, polarity=polarity,
                    phase=phase)
     self.msgbuf = bytearray(32)
     self.status = bytearray(4)
开发者ID:SpotlightKid,项目名称:micropython-stm-lib,代码行数:7,代码来源:spimaster.py

示例14: __init__

    def __init__(self, cs='PE3', spi=1, debug=False):
        self._debug = debug
        self.cs_pin = Pin(cs, Pin.OUT_PP, Pin.PULL_NONE)
        self.cs_pin.high()
        self.spi = SPI(spi, SPI.MASTER, baudrate=328125, polarity=0, phase=1,
                       bits=8)

        self.read_id()
        # First SPI read always returns 255 --> discard and read ID again
        self.who_am_i = self.read_id()
        self.debug("Accel-ID: %s" % self.who_am_i)

        if self.who_am_i == LIS302DL_WHO_AM_I_VAL:
            self.write_bytes(LIS302DL_CTRL_REG1_ADDR, LIS302DL_CONF)
            self.sensitivity = 18
        elif self.who_am_i == LIS3DSH_WHO_AM_I_VAL:
            self.write_bytes(LIS3DSH_CTRL_REG4_ADDR, LIS3DSH_CTRL_REG4_CONF)
            self.write_bytes(LIS3DSH_CTRL_REG5_ADDR, LIS3DSH_CTRL_REG5_CONF)
            self.sensitivity = 0.06 * 256
        else:
            msg = 'LIS302DL or LIS3DSH accelerometer not present'

            if self._debug:
                self.debug(msg)
            else:
                raise IOError(msg)
开发者ID:EMATech,项目名称:micropython-stm-lib,代码行数:26,代码来源:staccel.py

示例15: __init__

 def __init__(self):
     self.cs_pin = Pin('PE3', Pin.OUT_PP, Pin.PULL_NONE)
     self.cs_pin.high()
     self.spi = SPI(1, SPI.MASTER, baudrate=328125, polarity=0, phase=1, bits=8)
     self.write_bytes(LIS302DL_CTRL_REG1_ADDR, bytearray([LIS302DL_CONF]))
     if self.read_id() != LIS302DL_WHO_AM_I_VAL:
         raise Exception('LIS302DL accelerometer not present')
开发者ID:magickcoding,项目名称:micropython,代码行数:7,代码来源:staccel.py


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