本文整理汇总了Python中machine.Pin.on方法的典型用法代码示例。如果您正苦于以下问题:Python Pin.on方法的具体用法?Python Pin.on怎么用?Python Pin.on使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类machine.Pin
的用法示例。
在下文中一共展示了Pin.on方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Ultrasonic
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import on [as 别名]
class Ultrasonic(object):
def __init__(self, trigger_pin, echo_pin, timeout_us=30000):
# WARNING: Don't use PA4-X5 or PA5-X6 as echo pin without a 1k resistor
# Default timeout is a bit more than the HC-SR04 max distance (400 cm):
# 400 cm * 29 us/cm (speed of sound ~340 m/s) * 2 (round-trip)
self.timeout = timeout_us
# Init trigger pin (out)
self.trigger = Pin(trigger_pin, mode=Pin.OUT, pull=None)
self.trigger.off()
# Init echo pin (in)
self.echo = Pin(echo_pin, mode=Pin.IN, pull=None)
def distance_in_inches(self):
return (self.distance_in_cm() * 0.3937)
def distance_in_cm(self):
# Send a 10us pulse
self.trigger.on()
sleep_us(10)
self.trigger.off()
# Wait for the pulse and calc its duration
time_pulse = time_pulse_us(self.echo, 1, self.timeout)
if time_pulse < 0:
raise MeasurementTimeout(self.timeout)
# Divide the duration of the pulse by 2 (round-trip) and then divide it
# by 29 us/cm (speed of sound = ~340 m/s)
return (time_pulse / 2) / 29
示例2: Pin
# 需要导入模块: from machine import Pin [as 别名]
# 或者: from machine.Pin import on [as 别名]
# NeoPixelをいくつか(1セグ4個くらい)つないで7セグにし、大会用のタイマーにする。
# 7セグのaからbcdefgと順番に信号線で一直列につなぐ。7セグ1桁のタイマー。
# 残10分から表示し、時間ぎれで点滅+ブザー鳴らす。
# 2017-03-21 by penkich
#
from machine import Pin,I2C,Timer
from neopixel import NeoPixel
import time
npix = 4 # 1セグを構成するNeoPixelの個数
t = 50 # 時間設定(分)
pin = Pin(4,Pin.OUT) # NeoPixelの信号線を接続
np = NeoPixel(pin, 7 * npix)
buz = Pin(5,Pin.OUT) # 圧電ブザーを接続
buz.on() # 起動時に少し鳴らす
time.sleep(1)
buz.off()
def seg7(n,rgb):
data = [0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe4,0xfe,0xe6,0xee]
x = data[n] >> 1
out = []
for i in range(7):
if x % 2:
out.append(rgb)
else:
out.append(blank)
x = x >> 1
out.reverse()
tmp = []