本文整理汇总了Python中machine.Pin.value方法的典型用法代码示例。如果您正苦于以下问题:Python Pin.value方法的具体用法?Python Pin.value怎么用?Python Pin.value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类machine.Pin
的用法示例。
在下文中一共展示了Pin.value方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import value [as 别名]
class Button:
def __init__(self, pin):
from machine import Pin
self.pin = Pin(pin, Pin.IN)
def get_presses(self, delay = 1):
last_time, last_state, presses = time.time(), 0, 0
while time.time() < last_time + delay:
time.sleep_ms(50)
if last_state == 0 and self.pin.value() == 1:
last_state = 1
if last_state == 1 and self.pin.value() == 0:
last_state, presses = 0, presses + 1
return presses
def is_pressed(self):
return self.pin.value() == 0
def was_pressed(self):
last_state = self.pin.value()
time.sleep_ms(15)
if last_state == 1 and self.pin.value() == 0:
return True
return False
def irq(self, handler, trigger):
self.pin.irq(handler = handler, trigger = trigger)
示例2: near
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import value [as 别名]
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
示例3: TB6612FNG
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import value [as 别名]
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)
示例4: test
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import value [as 别名]
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()
示例5: __init__
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import value [as 别名]
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)
示例6: main
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import value [as 别名]
def main():
# set internal clock
rtc = settime(timezone_offset=TIMEZONE_OFFSET)
year, month, day, hour, minute, second, *_ = rtc.now()
trigger = Pin('GP5', mode=Pin.OUT)
trigger.value(0)
# initial trigger timer
timer = Timer(3, mode=Timer.PERIODIC, width=32)
timer_channel = timer.channel(Timer.A | Timer.B, period=30000000)
timer_channel.irq(handler=lambda t: trigger.toggle(), trigger=Timer.TIMEOUT)
try:
while True:
leds = clock2matrix(hour=hour, minute=minute).columns
# led matrix multiplexing
current_trigger = trigger.value()
while trigger.value() == current_trigger:
for col in leds:
latch.value(0)
# write current time
spi.write(col)
# update LEDs
latch.value(1)
sleep_ms(1)
latch.value(0)
spi.write(OFF)
latch.value(1)
sleep_us(50)
latch.value(0)
spi.write(OFF)
latch.value(1)
year, month, day, hour, minute, second, *_ = rtc.now()
# update rtc at 04:00
if hour == 4 and minute == 0:
rtc = settime(timezone_offset=TIMEZONE_OFFSET)
except Exception as e:
matrix_off()
while True:
print(e)
sleep_ms(2000)
示例7: __init__
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import value [as 别名]
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
示例8: isLight
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import value [as 别名]
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
示例9: __init__
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import value [as 别名]
class Sonar:
def __init__(self,trig,echo):
self.trig=Pin(trig,Pin.OUT)
self.echo=Pin(echo,Pin.IN)
def checkdist(self):
self.trig.value(0)
self.echo.value(0)
self.trig.value(1)
time.sleep_us(10)
self.trig.value(0)
while(self.echo.value()==0):
pass
t1=time.ticks_us()
while(self.echo.value()==1):
pass
t2=time.ticks_us()
return round(time.ticks_diff(t2,t1)/10000*340/2,2)
示例10: Buzz
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import value [as 别名]
class Buzz(object):
def __init__(self,pin=6):
self.id=pins_remap_esp32[pin]
self.io=Pin(self.id)
self.io.value(1)
self.isOn=False
def on(self,freq=500):
if self.isOn is False:
self.pwm=PWM(self.io,freq,512)
self.isOn=True
def off(self):
if self.isOn:
self.pwm.deinit()
self.io.init(self.id,Pin.OUT)
self.io.value(1)
self.isOn=False
def freq(self,freq):
self.pwm.freq(freq)
示例11: __init__
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import value [as 别名]
class DistanceSensor:
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
def isDistanceCalculated(self):
return self.mm != -1 & self.cm != -1
def setTriggerPinValue(self, value):
self.triggerPin.value(value)
def getDistanceString(self):
return str(self.cm) + "," + self.mm_decimal + str(self.mm) + "cm"
def changingEdge(self, pin):
global callback
# Get the flag which enabled to IRQ
flags = callback.flags()
# If rising, start count the time
if flags & Pin.IRQ_RISING:
self.raising_time = time.ticks_us()
# If falling edge, then stop counting the time and calculate the distance
elif flags & Pin.IRQ_FALLING:
self.falling_time = time.ticks_us()
# Get the ellapsed time between RISING and FALLING
delay = time.ticks_diff(self.raising_time, self.falling_time)
# We use 17 instead of 0,017
distance = delay * 17
# We rescale the distance in cm by separating cm and mm
self.cm = distance // 1000
self.mm = distance % 1000
#in case we have a distance like 49028
# cm = 49
# mm = 028 but the 0 would be discared so we check it
if distance % 100 == distance % 1000:
self.mm_decimal = "0"
示例12: output
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import value [as 别名]
class output(object):
def __init__(self,name,config,callback):
# mode = config.get('MODE', 'OUTPUT')
port = config.get('PORT', 1)
self._name = name
self._callback = callback
print('GPIO-output',port,config,name,callback)
self._gpio = Pin(port, Pin.OUT)
def run(self):
while True:
yield
def SET(self,value):
if 'ON' in value:
self._gpio.value(1)
else:
self._gpio.value(0)
#self._gpio.off()
# print('GET METHode VALUE',value)
return True
示例13: nvic_set_prio
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import value [as 别名]
nvic_set_prio(-1, 1)
nvic_set_prio(25, 0)
# probably want to enable-preload (ARR, CCR1, etc), then load next set of values, then CEN
# because after n-pulses, UEV fires...
# then in a UEV interrupt (??) we can load the next set of values via DMA/memory, and re-CEN (unless there are no more data from DMA/memory)
#import dump_regs
#dump_regs.dump_regs()
# make sure PA0 PA1, PA2 are output LO state
timers_init()
YEL_LED.value(1)
EN_18V_ONBOARD.value(1)
#EN_18V_U4.value(0)
pyb.delay(900)
YEL_LED.value(0)
EN_18V_ONBOARD.value(0)
#EN_18V_U4.value(1)
pyb.delay(2000)
YEL_LED.value(1)
#EN_18V_U4.value(0)
示例14: EPD
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import value [as 别名]
class EPD(object):
MAX_READ = 45
SW_NORMAL_PROCESSING = 0x9000
EP_FRAMEBUFFER_SLOT_OVERRUN = 0x6a84 # too much data fed in
EP_SW_INVALID_LE = 0x6c00 # Wrong expected length
EP_SW_INSTRUCTION_NOT_SUPPORTED = 0x6d00 # bad instr
EP_SW_WRONG_PARAMETERS_P1P2 = 0x6a00
EP_SW_WRONG_LENGTH = 0x6700
DEFAULT_SLOT=0 # always the *oldest*, should wear-level then I think
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
def enable(self):
self.tc_en_bar.value(0) # Power up
time.sleep_ms(5)
while self.tc_busy_bar() == 0:
machine.idle() # will it wake up here?
# /tc_busy goes high during startup, low during init, then high when not busy
def disable(self):
self.tc_en_bar.value(1) # Off
def send_command(self, ins, p1, p2, data=None, expected=None):
# These command variables are always sent
cmd = struct.pack('3B', ins, p1, p2)
# Looks like data is only sent with the length (Lc)
if data:
assert len(data) <= 251 # Thus speaks the datasheet
cmd += struct.pack('B', len(data))
cmd += data
# Expected data is either not present at all, 0 for null-terminated, or a number for fixed
if expected is not None:
cmd += struct.pack('B', expected)
if self.debug:
print("Sending: " + hexlify(cmd).decode())
self.spi.write(cmd)
# Wait for a little while
time.sleep_us(15) # This should take at most 14.5us
while self.tc_busy_bar() == 0:
machine.idle()
# Request a response
if expected is not None:
if expected > 0:
result_bytes = self.spi.read(2 + expected)
else:
result_bytes = self.spi.read(EPD.MAX_READ)
strlen = result_bytes.find(b'\x00')
result_bytes = result_bytes[:strlen] + result_bytes[strlen+1:strlen+3]
else:
result_bytes = self.spi.read(2)
if self.debug:
print("Received: " + hexlify(result_bytes).decode())
(result,) = struct.unpack_from('>H', result_bytes[-2:])
if result != EPD.SW_NORMAL_PROCESSING:
raise ValueError("Bad result code: 0x%x" % result)
return result_bytes[:-2]
@staticmethod
def calculate_checksum(data, skip=16):
"""
Initial checksum value is 0x6363
#.........这里部分代码省略.........
示例15: print
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import value [as 别名]
fCsv.write(msg)
fCsv.write('\n')
fCsv.flush()
print(msg) # show in repl
count = count + 1
s.close()
time.sleep(0.3) #<== Try a delay here...
# -----------------------------
# add button manager
if button() == 1:
# pushbutton pressed
if pressed == 1:
continue
# pushbutton pressed
pycom.rgbled(0x7f0000) # red
# switch on the user LED
user_led.value(1)
# print("---------------------------- button pressed !!")
pressed = 1
else:
# pushbutton released
pycom.rgbled(0x007f00) # green
# switch off the user LED
user_led.value(0)
pressed = 0