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


Python Pin.high方法代码示例

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


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

示例1: start

# 需要导入模块: from pyb import Pin [as 别名]
# 或者: from pyb.Pin import high [as 别名]
    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,代码行数:27,代码来源:motor_class.py

示例2: Relay

# 需要导入模块: from pyb import Pin [as 别名]
# 或者: from pyb.Pin import high [as 别名]
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,代码行数:27,代码来源:Relay.py

示例3: ultrasound

# 需要导入模块: from pyb import Pin [as 别名]
# 或者: from pyb.Pin import high [as 别名]
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,代码行数:34,代码来源:full.py

示例4: __init__

# 需要导入模块: from pyb import Pin [as 别名]
# 或者: from pyb.Pin import high [as 别名]
class ScopePin:
    def __init__(self, pin_name):
        self.pin = Pin(pin_name, Pin.OUT_PP)
        self.pin.low()

    def pulse(self, n=1):
        for i in range(n):
            self.pin.high()
            self.pin.low()
开发者ID:pramasoul,项目名称:micropython-xbee,代码行数:11,代码来源:utils.py

示例5: drive_motor

# 需要导入模块: from pyb import Pin [as 别名]
# 或者: from pyb.Pin import high [as 别名]
def  drive_motor():
	A1 = Pin('Y9',Pin.OUT_PP)
	A2 = Pin('Y10',Pin.OUT_PP)
	A1.high()
	A2.low()
	motor = Pin('X1')
	tim = Timer(2, freq = 1000)
	ch = tim.channel(1, Timer.PWM, pin = motor)
	while True:
		ch.pulse_width_percent(50)
开发者ID:old-blighty,项目名称:de1-electonics-group-project,代码行数:12,代码来源:full.py

示例6: __init__

# 需要导入模块: from pyb import Pin [as 别名]
# 或者: from pyb.Pin import high [as 别名]
class vactrolControl:
    """simple class providing on/off functionality of a vactrol
    controlled by a pyboard bin.
    """
    def __init__(self, vactrolPin):
        self.vactrol = Pin(vactrolPin, Pin.OUT_PP)
        self.vactrol.low()

    def on(self):
        self.vactrol.high()

    def off(self):
        self.vactrol.low()
开发者ID:P3PO,项目名称:ArduGuitar,代码行数:15,代码来源:vactrolControl.py

示例7: motor_control

# 需要导入模块: from pyb import Pin [as 别名]
# 或者: from pyb.Pin import high [as 别名]
def motor_control():
	# define various I/O pins for ADC
	adc_1 = ADC(Pin('X19'))
	adc_2 = ADC(Pin('X20'))

	# set up motor with PWM and timer control
	A1 = Pin('Y9',Pin.OUT_PP)
	A2 = Pin('Y10',Pin.OUT_PP)
	pwm_out = Pin('X1')
	tim = Timer(2, freq = 1000)
	motor = tim.channel(1, Timer.PWM, pin = pwm_out)
	
	A1.high()	# motor in brake position
	A2.high()

	# Calibrate the neutral position for joysticks
	MID = adc_1.read()		# read the ADC 1 value now to calibrate
	DEADZONE = 10	# middle position when not moving
	
	# Use joystick to control forward/backward and speed
	while True:				# loop forever until CTRL-C
		speed = int(100*(adc_1.read()-MID)/MID)
		if (speed >= DEADZONE):		# forward
			A1.high()
			A2.low()
			motor.pulse_width_percent(speed)
		elif (speed <= -DEADZONE):
			A1.low()		# backward
			A2.high()
			motor.pulse_width_percent(-speed)
		else:
			A1.low()		# stop
			A2.low()		
开发者ID:old-blighty,项目名称:de1-electonics-group-project,代码行数:35,代码来源:full.py

示例8: flash_LEDs

# 需要导入模块: from pyb import Pin [as 别名]
# 或者: from pyb.Pin import high [as 别名]
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,代码行数:16,代码来源:full.py

示例9: __init__

# 需要导入模块: from pyb import Pin [as 别名]
# 或者: from pyb.Pin import high [as 别名]
class SpiMaster:
    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)

    def write_status(self, status):
        self.ss.low()
        self.spi.send(0x01)
        self.spi.send(status & 0xFF)
        self.spi.send((status >> 8) & 0xFF)
        self.spi.send((status >> 16) & 0xFF)
        self.spi.send((status >> 24) & 0xFF)
        self.ss.high()

    def read_status(self):
        self.ss.low()
        self.spi.send(0x04)
        self.spi.recv(self.status)
        self.ss.high()
        return (
            self.status[0] |
            (self.status[1] << 8) |
            (self.status[2] << 16) |
            (self.status[3] << 24)
        )

    def read_data(self):
        self.ss.low()
        self.spi.send(0x03)
        self.spi.send(0x00)
        self.spi.recv(self.msgbuf)
        self.ss.high()
        return self.msgbuf

    def read_msg(self, encoding='utf-8'):
        return bytes(self.read_data()).strip('\0').decode(encoding)

    def write_data(self, data):
        self.msgbuf[:] = data[:32] + b'\0' * (32 - len(data[:32]))
        self.ss.low()
        self.spi.send(0x02)
        self.spi.send(0x00)
        self.spi.send(self.msgbuf)
        self.ss.high()
开发者ID:SpotlightKid,项目名称:micropython-stm-lib,代码行数:50,代码来源:spimaster.py

示例10: UltraSonicMeter

# 需要导入模块: from pyb import Pin [as 别名]
# 或者: from pyb.Pin import high [as 别名]
class UltraSonicMeter(object):

    def __init__(self):
        self.tmp = self.time = 0
        self.cnt = 0
        self.fr = 0
        self.trig = Pin('X12', Pin.OUT_PP, Pin.PULL_NONE)
        echoR = Pin('X1', Pin.IN, Pin.PULL_NONE)
        echoF = Pin('X2', Pin.IN, Pin.PULL_NONE)
        self.micros = pyb.Timer(5, prescaler=83, period=0x3fffffff)
        self.timer = Timer(2, freq=1000)
        self.timer.period(3600)
        self.timer.prescaler(1375)
        self.timer.callback(lambda e: self.run_trig())
        extR = ExtInt(echoR, ExtInt.IRQ_RISING, Pin.PULL_NONE, self.start_count)
        extF = ExtInt(echoF, ExtInt.IRQ_FALLING, Pin.PULL_NONE, self.read_dist)

    def run_trig(self):
        self.trig.high()
        pyb.udelay(1)
        self.trig.low()

    def start_count(self, line):
        self.micros.counter(0)
        self.time = self.micros.counter()
        self.timer.counter(0)

    def read_dist(self, line):
        end = self.micros.counter()
        micros = end-self.time
        distP1 = micros//5
        distP2 = micros//6
        distP3 = (distP1-distP2)//10*2
        dist = distP2+distP3

        if dist != 0:
            self.cnt += 1
            self.fr += dist

        if self.cnt == 15:
            tmp = self.tmp
            dist = self.fr//self.cnt
            if tmp != dist:
                print(dist, 'mm')
                self.tmp = dist
            self.cnt = 0
            self.fr  = 0
开发者ID:mchobby,项目名称:pyboard_drive,代码行数:49,代码来源:HC-SR04.py

示例11: __init__

# 需要导入模块: from pyb import Pin [as 别名]
# 或者: from pyb.Pin import high [as 别名]
	def __init__(self):
		self.dbg = Pin("X9", Pin.OUT_PP)
		self.dbg.low()
		self.spi = SPI(2, SPI.MASTER, baudrate=5250000)
		ss = Pin(self.CS_TFT, Pin.OUT_PP)
		ss.low()
		self.dc = Pin(self.DC, Pin.OUT_PP)
		self.dc.low()
		self.DC_flag = False
		cs_sd = Pin(self.CS_SD, Pin.OUT_PP)
		cs_sd.high()
		self.lite = Pin(self.LITE, Pin.OUT_PP)
		self.lite.high()
		reset = Pin(self.RST, Pin.OUT_PP)
		reset.low()
		delay(2)
		reset.high()
		delay(200)
开发者ID:salskraken,项目名称:typsnitt,代码行数:20,代码来源:Lib_simple.py

示例12: __init__

# 需要导入模块: from pyb import Pin [as 别名]
# 或者: from pyb.Pin import high [as 别名]
class Motor:
    def __init__(self, pinA, pinB):
        self._a = Pin(pinA, Pin.OUT_PP) #todo: check motor driver pins for internal pull resistors. or use pyboard pin pulling and open drain?
        self._b = Pin(pinB, Pin.OUT_PP)
        self.stop()

    # defaults to connect both terminals to GND, but can override to VCC
    def stop(self, val = False):
        self._a.value(val)
        self._b.value(val)

    def drive(self, direction):
        if direction > 0:
            self._a.high()
            self._b.low()
        elif direction == 0:
            self.stop()
        elif direction < 0:
            self._a.low()
            self._b.high()
开发者ID:jradtilbrook,项目名称:DUObot,代码行数:22,代码来源:motor.py

示例13: init

# 需要导入模块: from pyb import Pin [as 别名]
# 或者: from pyb.Pin import high [as 别名]
def init(timer_id=2, data_pin='Y2', the_dhttype='DHT22'):
    global _dataDHT
    global micros
    global timer
    global dhttype
    
    if (the_dhttype == 'DHT11'):
        dhttype = 0
    else:
        dhttype = 1
    # Configure the pid for data communication
    _dataDHT = Pin(data_pin)
    # Save the ID of the timer we are going to use
    _dataDHT = timer_id
    # setup the 1uS timer
    micros = pyb.Timer(timer, prescaler=83, period=0x3fffffff)  # 1MHz ~ 1uS
    # Prepare interrupt handler
    ExtInt(_dataDHT, ExtInt.IRQ_FALLING, Pin.PULL_UP, None)
    ExtInt(_dataDHT, ExtInt.IRQ_FALLING, Pin.PULL_UP, _interuptHandler)
    _dataDHT.high()
    pyb.delay(250)
开发者ID:letouriste001,项目名称:SmartForest_2.0,代码行数:23,代码来源:DHTSeries.py

示例14: pins_test

# 需要导入模块: from pyb import Pin [as 别名]
# 或者: from pyb.Pin import high [as 别名]
def pins_test():
    i2c = I2C(1, I2C.MASTER)
    spi = SPI(2, SPI.MASTER)
    uart = UART(3, 9600)
    servo = Servo(1)
    adc = ADC(Pin.board.X3)
    dac = DAC(1)
    pin = Pin('X4', mode=Pin.AF_PP, af=Pin.AF3_TIM9)
    pin = Pin('Y1', mode=Pin.AF_OD, af=3)
    pin = Pin('Y2', mode=Pin.OUT_PP)
    pin = Pin('Y3', mode=Pin.OUT_OD, pull=Pin.PULL_UP)
    pin.high()
    pin = Pin('Y4', mode=Pin.OUT_OD, pull=Pin.PULL_DOWN)
    pin.high()
    pin = Pin('X18', mode=Pin.IN, pull=Pin.PULL_NONE)
    pin = Pin('X19', mode=Pin.IN, pull=Pin.PULL_UP)
    pin = Pin('X20', mode=Pin.IN, pull=Pin.PULL_DOWN)
    print('===== output of pins() =====')
    pins()
    print('===== output of af() =====')
    af()
开发者ID:AbhinayBandaru,项目名称:upy-examples,代码行数:23,代码来源:pin_dump.py

示例15: __init__

# 需要导入模块: from pyb import Pin [as 别名]
# 或者: from pyb.Pin import high [as 别名]
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,代码行数:60,代码来源:staccel.py


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