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


Python Pin.value方法代码示例

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


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

示例1: ultrasound

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

示例2: __init__

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

示例3: __init__

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

示例4: Relay

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

示例5: __init__

# 需要导入模块: from pyb import Pin [as 别名]
# 或者: from pyb.Pin import value [as 别名]
class JoyStick:
    # expo formula
    # ouput =((EXPO*POW(input,3))+((1-EXPO)*input))*RATE
    # where input & output are on  [-1,1]
    
    def __init__(self,xp,yp, pbp, pbFunc):  # last arg is a pointer to the interrupt handler
         self.XPin = ADC(Pin(xp))
         self.YPin = ADC(Pin(yp))
         self.PBPin = Pin(pbp, Pin.IN, Pin.PULL_UP)
                          
         self.maxAnalog = 4095
         self.minAnalog = 0
         self.maxOutput = 100
         self.minOutput = -100
         self.pinExpo = 25

         self.onPB = pbFunc
         self.changeDelta   = 400   # ms
         self.lastChangeTime = 0    # ms

         self._calibrateXY()

    def _calibrateXY(self):
        xSum = 0
        ySum = 0

        for i in range(100):
            xSum += self.XPin.read()
            ySum += self.YPin.read()

        self.X0 = round(xSum/100.0)
        self.Y0 = round(ySum/100.0)

    def checkPB(self):
        now = time.ticks_ms()
        if now-self.lastChangeTime > self.changeDelta:
            if not self.PBPin.value():
                self.onPB()
                self.lastChangeTime = now
                
    def _read(self, x):
        pin = self.XPin
        V0 =  self.X0
        if not x:
            pin = self.YPin
            V0 =  self.Y0
            
        val = pin.read()
        if abs(val - V0) < self.pinExpo:
            return(0)
        return arduino_map(val,V0,self.maxAnalog,0,self.maxOutput) \
            if val > self.X0 else \
               arduino_map(val,self.minAnalog,V0,self.minOutput,0) 

    def readX(self):
        return self._read(True)
    def readY(self):
        return self._read(False)
开发者ID:gratefulfrog,项目名称:ArduGuitar,代码行数:60,代码来源:joystick.py

示例6: check_joystick

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

示例7: __init__

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

示例8: __init__

# 需要导入模块: from pyb import Pin [as 别名]
# 或者: from pyb.Pin import value [as 别名]
class TrackBall:
    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))
            
    def x11(self,unused):
        if self.x2.value():
            print('X axis:\t-1')
        else:
            print('X axis:\t+1')

    def y11(self,unused):
        if self.y2.value():
            print('Y axis:\t-1')
        else:
            print('Y axis:\t+1')

    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,代码行数:40,代码来源:trackballTest.py

示例9: __init__

# 需要导入模块: from pyb import Pin [as 别名]
# 或者: from pyb.Pin import value [as 别名]
class RC:
  start = width = last_width = 0
  def __init__(self, index):
    timer = timers[rc_pins_timers[index]]
    self.pin = Pin(rc_pins[index])
    self.channel = timer.channel(rc_pins_channels[index],
                                 Timer.IC,
                                 pin=self.pin,
                                 polarity=Timer.BOTH)
    self.channel.callback(self.callback)
  def callback(self, timer):
    if self.pin.value(): self.start = self.channel.capture()
    else: self.width = self.channel.capture() - self.start & 0x0fffffff
  def get_width(self):
    w = self.width
    self.last_width = w if w > 950 and w < 1950 else self.last_width
    return self.last_width
  def __del__(self):
    self.timer.deinit()
开发者ID:wagnerc4,项目名称:flight_controller,代码行数:21,代码来源:rc.py

示例10: callback1

# 需要导入模块: from pyb import Pin [as 别名]
# 或者: from pyb.Pin import value [as 别名]


############### BASIC LED on off #############

r.on()
r.off()

g.on()
g.off()

b.on()
b.off()

#####################  read out button states ################
btn1.value()
btn2.value()


##################### define callbacks for buttons ################
def callback1(line):
  print("Callback 1: turn green led ON")
  g.on()

def callback2(line):
  print("Callback 1: turn green led OFF")
  g.off()

extint1 = pyb.ExtInt(btn1, pyb.ExtInt.IRQ_FALLING, pyb.Pin.PULL_DOWN, callback1)
extint2 = pyb.ExtInt(btn2, pyb.ExtInt.IRQ_FALLING, pyb.Pin.PULL_DOWN, callback2)
开发者ID:mbag,项目名称:meetup,代码行数:31,代码来源:tutorial01.py

示例11: Pin

# 需要导入模块: from pyb import Pin [as 别名]
# 或者: from pyb.Pin import value [as 别名]
from pyb import Pin, Timer


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				# timestamp at rising edge of echo
end = 0					# timestamp at falling edge of echo

while True:
	# Send a 20usec pulse every 10ms
	Trigger.high()
	pyb.udelay(20) #udelay uses argument in microseconds
	Trigger.low()

	# Wait until echo pulse goes from low to high
	while Echo.value() == 0:
		start = micros.counter()	# record start time of pulse

	# Wait until echo pulse goes from high to low
	while Echo.value() == 1:   # do nothing
		end = micros.counter()		# record end time of pulse

	# Calculate distance from delay duration
	distance = int(((end - start) / 2) / 29)
	print('Distance: ', distance, ' cm')
	pyb.delay(500)
开发者ID:old-blighty,项目名称:de1-electonics-group-project,代码行数:32,代码来源:task5.py

示例12: __init__

# 需要导入模块: from pyb import Pin [as 别名]
# 或者: from pyb.Pin import value [as 别名]
class SC1602:
    sc1602pin_default = {
        'RS': Pin.board.PE4,
        'E': Pin.board.PE5,
        'DB0': Pin.board.PE7,
        'DB1': Pin.board.PE8,
        'DB2': Pin.board.PE9,
        'DB3': Pin.board.PE10,
        'DB4': Pin.board.PE11,
        'DB5': Pin.board.PE12,
        'DB6': Pin.board.PE13,
        'DB7': Pin.board.PE14,
    }

    def __init__(self, pin=None):
        Pin.dict(pin or self.sc1602pin_default)
        self.rs = Pin("RS", Pin.OUT_PP)
        self.e = Pin("E", Pin.OUT_PP)
        self.db0 = Pin("DB0", Pin.OUT_PP)
        self.db1 = Pin("DB1", Pin.OUT_PP)
        self.db2 = Pin("DB2", Pin.OUT_PP)
        self.db3 = Pin("DB3", Pin.OUT_PP)
        self.db4 = Pin("DB4", Pin.OUT_PP)
        self.db5 = Pin("DB5", Pin.OUT_PP)
        self.db6 = Pin("DB6", Pin.OUT_PP)
        self.db7 = Pin("DB7", Pin.OUT_PP)

        self.e.low()

    def initialize(self):
        for _ in range(3):
            self.rs.low()
            self.__set_databus(0x30)
            self.__enable()
            pyb.delay(5)
        
        # function set
        self.rs.low()
        self.__set_databus(0x38)
        self.__enable()

        self.display_on_off(False)
        self.clear()
        self.display_on_off(True)

        # entry mode set
        self.rs.low()
        self.__set_databus(0x06)
        self.__enable()

    def __set_databus(self, data):
        self.db0.value(data & 1)
        self.db1.value((data >> 1) & 1)
        self.db2.value((data >> 2) & 1)
        self.db3.value((data >> 3) & 1)
        self.db4.value((data >> 4) & 1)
        self.db5.value((data >> 5) & 1)
        self.db6.value((data >> 6) & 1)
        self.db7.value((data >> 7) & 1)

    def __enable(self):
        self.e.high()
        pyb.udelay(1)
        self.e.low()
        pyb.udelay(40)

    def clear(self):
        self.rs.low()
        self.__set_databus(1)
        self.__enable()
        pyb.udelay(1600)

    def cursor_at_home(self):
        self.rs.low()
        self.__set_databus(2)
        self.__enable()
        pyb.udelay(1600)

    def display_on_off(self, display, cursor=False, blink=False):
        self.rs.low()
        self.__set_databus(8)

        if display:
            self.db2.high()
        if cursor:
            self.db1.high()
        if blink:
            self.db0.high()

        self.__enable()

    def set_cursor(self, y, x=0):
        self.rs.low()
        self.__set_databus((y * 0x40 + x) | 0x80)
        self.__enable()

    def putc(self, c):
        self.rs.high()
        self.__set_databus(ord(c))
        self.__enable()
#.........这里部分代码省略.........
开发者ID:idobatter,项目名称:micropython_modules,代码行数:103,代码来源:sc1602.py

示例13: print

# 需要导入模块: from pyb import Pin [as 别名]
# 或者: from pyb.Pin import value [as 别名]
uart.init(9600, bits=7, parity=1, stop=1) 
start_pressed = 0
# stop_pressed = 0
t1_set = 200
t1_last = 30
t2_set = 600
t1_t2_step = 1
t1_t2_last = 480
t2_last = 120
off_last = 390
cmd_prefix = '*P012' # Write to RAM of point 1 with positive sign and decimal point 2
cmd_standby = '*D03' # Standby mode with output off
cmd_dis_standby = '*E03'# Disable standby
start_value = 0
stop_value = 0
print("stop_pin.value="+str(stop_pin.value()))
print("start_pin.value="+str(start_pin.value()))

def start_callback(line):
  
  global start_pressed, start_int, pyb, start_pin, stop_pin
  

  #print("%d"%start_pin.value())
  if ((start_pin.value() == 0) and (stop_pin.value() == 1)): # 1 = not pressed
    start_int.disable()
    start_pressed = 1
    print("start_pressed=========")
    #pyb.hard_reset()
  else:
    #start_pressed = 0
开发者ID:bittware,项目名称:temp_ctrl,代码行数:33,代码来源:main_iseries_temp_controller_rev1.0.py

示例14: SR04Distance

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

  maxinches = 20 #maximum range of SR04.

  def __init__( self, tpin, epin, timer=2 ) :
    """  """

    if type(tpin) == str:
      self._tpin = Pin(tpin, Pin.OUT_PP, Pin.PULL_NONE)
    elif type(tpin) == Pin:
      self._tpin = tpin
    else:
      raise Exception("trigger pin must be pin name or pyb.Pin configured for output.")

    self._tpin.low()

    if type(epin) == str:
      self._epin = Pin(epin, Pin.IN, Pin.PULL_NONE)
    elif type(epin) == Pin:
      self._epin = epin
    else:
      raise Exception("echo pin must be pin name or pyb.Pin configured for input.")

    # Create a microseconds counter.
    self._micros = Timer(timer, prescaler=83, period=0x3fffffff)

  def __del__( self ) :
    self._micros.deinit()

  @property
  def counter( self ) : return self._micros.counter()

  @counter.setter
  def counter( self, value ) : self._micros.counter(value)

  @property
  def centimeters( self ) :
    start = 0
    end = 0

    self.counter = 0

    #Send 10us pulse.
    self._tpin.high()
    udelay(10)
    self._tpin.low()

    while not self._epin.value():
      start = self.counter

    j = 0

    # Wait 'till the pulse is gone.
    while self._epin.value() and j < 1000:
      j += 1
      end = self.counter

    # Calc the duration of the recieved pulse, divide the result by
    # 2 (round-trip) and divide it by 29 (the speed of sound is
    # 340 m/s and that is 29 us/cm).
    return (end - start) / 58

  @property
  def inches( self ) : return self.centimeters * 0.3937
开发者ID:rolandvs,项目名称:GuyCarverMicroPythonCode,代码行数:67,代码来源:SR04Distance.py

示例15: test_noinit

# 需要导入模块: from pyb import Pin [as 别名]
# 或者: from pyb.Pin import value [as 别名]
def test_noinit():
    for p in pin_map:
        pin = Pin(p)
        pin.value()
开发者ID:noahchense,项目名称:micropython,代码行数:6,代码来源:pin.py


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