本文整理汇总了Python中utime.sleep_ms函数的典型用法代码示例。如果您正苦于以下问题:Python sleep_ms函数的具体用法?Python sleep_ms怎么用?Python sleep_ms使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sleep_ms函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: disconnect
def disconnect(self, timeout=5000):
self.mqtt.stop()
tmo = timeout / 100
while not self.mqtt.status()[0] == 0:
utime.sleep_ms(100)
tmo -= 1
if tmo == 0:
print(Feedback.ERR_TIMEOUT_MQTT)
return False
if self.wifi.isconnected():
self.wifi.disconnect()
tmo = timeout / 100
while self.wifi.isconnected():
utime.sleep_ms(100)
tmo -= 1
if tmo == 0:
print(Feedback.ERR_TIMEOUT_WIFI)
return False
self.wifi.active(False)
return True
开发者ID:Fri3dCamp,项目名称:badge,代码行数:25,代码来源:__init__.py
示例2: __init__
def __init__(self, i2c, addr=0x77):
self.i2c = i2c
self.addr = addr
self.chip_id = self.i2c.readfrom_mem(self.addr, 0xD0, 2)
# read calibration data from EEPROM
self._AC1 = unp('>h', self.i2c.readfrom_mem(self.addr, 0xAA, 2))[0]
self._AC2 = unp('>h', self.i2c.readfrom_mem(self.addr, 0xAC, 2))[0]
self._AC3 = unp('>h', self.i2c.readfrom_mem(self.addr, 0xAE, 2))[0]
self._AC4 = unp('>H', self.i2c.readfrom_mem(self.addr, 0xB0, 2))[0]
self._AC5 = unp('>H', self.i2c.readfrom_mem(self.addr, 0xB2, 2))[0]
self._AC6 = unp('>H', self.i2c.readfrom_mem(self.addr, 0xB4, 2))[0]
self._B1 = unp('>h', self.i2c.readfrom_mem(self.addr, 0xB6, 2))[0]
self._B2 = unp('>h', self.i2c.readfrom_mem(self.addr, 0xB8, 2))[0]
self._MB = unp('>h', self.i2c.readfrom_mem(self.addr, 0xBA, 2))[0]
self._MC = unp('>h', self.i2c.readfrom_mem(self.addr, 0xBC, 2))[0]
self._MD = unp('>h', self.i2c.readfrom_mem(self.addr, 0xBE, 2))[0]
# settings to be adjusted by user
self.oversample_setting = 3
self.baseline = 101325.0
# output raw
self.UT_raw = None
self.B5_raw = None
self.MSB_raw = None
self.LSB_raw = None
self.XLSB_raw = None
self.gauge = self.makegauge() # Generator instance
for _ in range(128):
next(self.gauge)
utime.sleep_ms(1)
开发者ID:spirkaa,项目名称:micropython-bmp180,代码行数:32,代码来源:bmp180.py
示例3: stop
def stop(self):
"""
Stops the LoRaWAN nano gateway.
"""
self._log('Stopping...')
# send the LoRa radio to sleep
self.lora.callback(trigger=None, handler=None)
self.lora.power_mode(LoRa.SLEEP)
# stop the NTP sync
self.rtc.ntp_sync(None)
# cancel all the alarms
self.stat_alarm.cancel()
self.pull_alarm.cancel()
# signal the UDP thread to stop
self.udp_stop = True
while self.udp_stop:
utime.sleep_ms(50)
# disable WLAN
self.wlan.disconnect()
self.wlan.deinit()
开发者ID:H-LK,项目名称:pycom-libraries,代码行数:26,代码来源:nanogateway.py
示例4: connect
def connect(self, timeout=10000):
self.wifi.active(True)
self.wifi.connect(self.wifi_ssid, self.wifi_password)
# -- wait until connected
tmo = timeout/100
while not self.wifi.isconnected():
utime.sleep_ms(100)
tmo -= 1
if tmo == 0:
print(Feedback.ERR_TIMEOUT_WIFI)
return False
# -- start mqtt
if self.mqtt.status()[0] == 0:
self.mqtt.start()
tmo = timeout / 100
while not self.mqtt.status()[0] == 2:
utime.sleep_ms(100)
tmo -= 1
if tmo == 0:
print(Feedback.ERR_TIMEOUT_MQTT)
return False
return True
开发者ID:Fri3dCamp,项目名称:badge,代码行数:26,代码来源:__init__.py
示例5: calibrate
def calibrate(self,count=256,delay=200):
self._offset=(0,0,0)
self._scale=(1,1,1)
reading=self.magnetic
minx=maxx=reading[0]
miny=maxy=reading[1]
minz=maxz=reading[2]
while count:
utime.sleep_ms(delay)
reading=self.magnetic
minx=min(minx,reading[0])
maxx=max(maxx,reading[0])
miny=min(miny,reading[1])
maxy=max(maxy,reading[1])
minz=min(minz,reading[2])
maxz=max(maxz,reading[2])
count-=1
offset_x=(maxx+minx)/2
offset_y=(maxy+miny)/2
offset_z=(maxz+minz)/2
self._offset=(offset_x,offset_y,offset_z)
avg_delta_x=(maxx-minx)/2
avg_delta_y=(maxy-miny)/2
avg_delta_z=(maxz-minz)/2
avg_delta=(avg_delta_x+avg_delta_y+avg_delta_z)/3
scale_x=avg_delta/avg_delta_x
scale_y=avg_delta/avg_delta_y
scale_z=avg_delta/avg_delta_z
self._scale=(scale_x,scale_y,scale_z)
return self._offset,self._scale
开发者ID:radiumray,项目名称:mdxly,代码行数:30,代码来源:mpu9250.py
示例6: show
def show(self, data, delay=200, time=400):
self.fill(0)
if type(data)==str:
DISPLAY_WIDTH = 16 # Display width in pixels.
DISPLAY_HEIGHT = 8 # Display height in pixels.
# Initialize LED matrix.
matrix = Display(i2c)
#matrix.clear()
# Initialize font renderer using a helper function to flip the Y axis
# when rendering so the origin is in the upper left.
def matrix_pixel(x, y):
matrix._pixel(x, y, 1)
with BitmapFont(DISPLAY_WIDTH, DISPLAY_HEIGHT, matrix_pixel) as bf:
# Global state:
for msg in data:
matrix.clear()
pos = DISPLAY_WIDTH # X position of the message start.
message_width = bf.width(msg) # Message width in pixels.
bf.text(msg, 5, 0) #change X position
matrix._show()
if len(data)>1:
utime.sleep_ms(delay)
elif type(data)==int:
pass
elif type(data)==type(Image.HEART):
# print("Image")
l = data.str.split(':')
for i in range(8):
for j in range(16):
if l[i][j] == '1':
self._pixel(j, i, 1)
else:
self._pixel(j, i, 0)
#print(l[i][j])
self._show()
开发者ID:radiumray,项目名称:mdxly,代码行数:35,代码来源:matrix.py
示例7: play_show
def play_show(tune, pin=27, display=matrix.display, duration=None):
from machine import Pin, PWM
from utime import sleep_ms
try:
pwm = PWM(Pin(pin))
if duration is None:
set_default(tune[0])
else:
set_duration(duration)
for tone in tune:
tone = tone.upper() # all to upper
if tone[0] not in Letter:
continue
if len(tone)==4:
display.showstatic(tone.replace(":",""))
else:
display.showstatic(tone)
m = midi(tone)
pwm.freq(m[0]) # set frequency
pwm.duty(m[1]) # set duty cycle
sleep_ms(m[1])
display.clear()
finally:
pwm.deinit()
开发者ID:radiumray,项目名称:mdxly,代码行数:25,代码来源:music_backup.py
示例8: show
def show(self,data,delay=200,time=400):
self.fill(0)
if type(data)==str:
DISPLAY_WIDTH=16
DISPLAY_HEIGHT=8
matrix=Display(i2c)
def matrix_pixel(x,y):
matrix._pixel(x,y,1)
with BitmapFont(DISPLAY_WIDTH,DISPLAY_HEIGHT,matrix_pixel)as bf:
for msg in data:
matrix.clear()
pos=DISPLAY_WIDTH
message_width=bf.width(msg)
bf.text(msg,5,0)
matrix._show()
if len(data)>1:
utime.sleep_ms(delay)
elif type(data)==int:
pass
elif type(data)==type(Image.HEART):
l=data.str.split(':')
for i in range(8):
for j in range(16):
if l[i][j]=='1':
self._pixel(j,i,1)
else:
self._pixel(j,i,0)
self._show()
开发者ID:radiumray,项目名称:mdxly,代码行数:28,代码来源:matrix.py
示例9: play
def play():
#
# pack of cards
# select N from pack of cards
for i in range(0, len(Master_Pack)):
Pack.append(Master_Pack[i])
deal(Number_of_cards_to_deal)
#print("Remaining: ", Pack)
#print("Selected: ", SelectedCards)
N = len(SelectedCards)
M = 0
Score = 0
print("")
print("Welcome to MicroPython Play your Cards Right")
print("============================================")
while M < (N-1):
#print("Turn: ", M)
if turn(M):
Score = Score + 1
#print("Score: ", Score)
M += 1
utime.sleep_ms(2000)
# move to next card...
print("Score: ", Score, "out of ", N-1)
# Tidy Up
for i in range(0, N):
del SelectedCards[0]
for i in range(0,len(Pack)):
del Pack[0]
utime.sleep_ms(1000)
red.off()
grn.off()
yel.on()
print("Bye")
开发者ID:CoderDojoOlney,项目名称:PYCR-MicroPython,代码行数:34,代码来源:game.py
示例10: angle
def angle(self, to_angle, speed=None, *servo_ids):
if len(servo_ids) == 0:
servo_ids = ServoJewel.ALL
if speed is None:
for s in servo_ids:
self.servos[s].angle(to_angle)
else:
longest_range = 0
ranges = {}
for s in servo_ids:
from_angle = self.servos[s].angle()
if from_angle < to_angle:
ranges[s] = list(range(int(from_angle), to_angle + 5, 5))
else:
ranges[s] = list(range(int(from_angle), to_angle - 5, -5))
if longest_range < len(ranges[s]):
longest_range = len(ranges[s])
for i in range(0, longest_range):
for s in servo_ids:
if i >= len(ranges[s]):
continue
self.servos[s].angle(ranges[s][i])
utime.sleep_ms(speed)
开发者ID:Fri3dCamp,项目名称:badge,代码行数:29,代码来源:servo_jewel.py
示例11: slave
def slave():
nrf = NRF24L01(SPI(2), Pin('Y5'), Pin('Y4'), payload_size=8)
nrf.open_tx_pipe(pipes[1])
nrf.open_rx_pipe(1, pipes[0])
nrf.start_listening()
print('NRF24L01 slave mode, waiting for packets... (ctrl-C to stop)')
while True:
machine.idle()
if nrf.any():
while nrf.any():
buf = nrf.recv()
millis, led_state = struct.unpack('ii', buf)
print('received:', millis, led_state)
for led in leds:
if led_state & 1:
led.on()
else:
led.off()
led_state >>= 1
utime.sleep_ms(15)
nrf.stop_listening()
try:
nrf.send(struct.pack('i', millis))
except OSError:
pass
print('sent response')
nrf.start_listening()
开发者ID:AriZuu,项目名称:micropython,代码行数:31,代码来源:nrf24l01test.py
示例12: blinkIt
def blinkIt():
pin2 = machine.Pin(2, machine.Pin.OUT)
for loopCount in range(10):
pin2.value(1)
utime.sleep_ms(500)
pin2.value(0)
utime.sleep_ms(500)
print("hello")
开发者ID:douggilliland,项目名称:lb-Python-Code,代码行数:8,代码来源:blinkLED.py
示例13: pwm_cycle
def pwm_cycle(led, duty, cycles):
duty_off = 20 - duty
for i in range(cycles):
if duty:
led.on()
utime.sleep_ms(duty)
if duty_off:
led.off()
utime.sleep_ms(duty_off)
开发者ID:Achimh3011,项目名称:micropython,代码行数:9,代码来源:soft_pwm.py
示例14: master
def master():
csn = Pin(cfg['csn'], mode=Pin.OUT, value=1)
ce = Pin(cfg['ce'], mode=Pin.OUT, value=0)
if cfg['spi'] == -1:
spi = SPI(-1, sck=Pin(cfg['sck']), mosi=Pin(cfg['mosi']), miso=Pin(cfg['miso']))
nrf = NRF24L01(spi, csn, ce, payload_size=8)
else:
nrf = NRF24L01(SPI(cfg['spi']), csn, ce, payload_size=8)
nrf.open_tx_pipe(pipes[0])
nrf.open_rx_pipe(1, pipes[1])
nrf.start_listening()
num_needed = 16
num_successes = 0
num_failures = 0
led_state = 0
print('NRF24L01 master mode, sending %d packets...' % num_needed)
while num_successes < num_needed and num_failures < num_needed:
# stop listening and send packet
nrf.stop_listening()
millis = utime.ticks_ms()
led_state = max(1, (led_state << 1) & 0x0f)
print('sending:', millis, led_state)
try:
nrf.send(struct.pack('ii', millis, led_state))
except OSError:
pass
# start listening again
nrf.start_listening()
# wait for response, with 250ms timeout
start_time = utime.ticks_ms()
timeout = False
while not nrf.any() and not timeout:
if utime.ticks_diff(utime.ticks_ms(), start_time) > 250:
timeout = True
if timeout:
print('failed, response timed out')
num_failures += 1
else:
# recv packet
got_millis, = struct.unpack('i', nrf.recv())
# print response and round-trip delay
print('got response:', got_millis, '(delay', utime.ticks_diff(utime.ticks_ms(), got_millis), 'ms)')
num_successes += 1
# delay then loop
utime.sleep_ms(250)
print('master finished sending; successes=%d, failures=%d' % (num_successes, num_failures))
开发者ID:DanielO,项目名称:micropython,代码行数:57,代码来源:nrf24l01test.py
示例15: iflush
def iflush(self):
t = 5000
while t:
self.i2c.readfrom_into(self.i2c_addr, self.buf16)
if self.buf16[0] == 0:
return
t -= 1
sleep_ms(1)
raise OSError(uerrno.ETIMEDOUT)
开发者ID:fabaff,项目名称:micropython,代码行数:9,代码来源:lcd160cr.py
示例16: blink
def blink(self, *eye_ids):
if len(eye_ids) == 0:
eye_ids = [0, 1]
for m in Eyes.BLINK_MASK:
for i in eye_ids:
self.matrices.mask[i] = m
utime.sleep_ms(50)
开发者ID:jantje,项目名称:badge,代码行数:9,代码来源:robot.py
示例17: run
def run(self):
while True:
iteration_start = utime.ticks_ms()
self.perform_tasks()
time_spent_on_tasks = utime.ticks_diff(utime.ticks_ms(), iteration_start)
if time_spent_on_tasks < self.sleep_ms:
utime.sleep_ms(utime.ticks_diff(self.sleep_ms, time_spent_on_tasks))
else:
logger.warning('Skipping sleep - spent {}ms on tasks'.format(time_spent_on_tasks))
开发者ID:wicol,项目名称:micropython-stuff,代码行数:9,代码来源:scheduler.py
示例18: _waitfor
def _waitfor(self, n, buf):
t = 5000
while t:
self.i2c.readfrom_into(self.i2c_addr, self.buf1)
if self.buf1[0] >= n:
self.i2c.readfrom_into(self.i2c_addr, buf)
return
t -= 1
sleep_ms(1)
raise OSError(uerrno.ETIMEDOUT)
开发者ID:fabaff,项目名称:micropython,代码行数:10,代码来源:lcd160cr.py
示例19: say_hello_left
def say_hello_left(self):
self.lean_to_left(ServoJewel.SPEED_SLOW)
for i in range(0, 3):
self.servos.angle(MAX, ServoJewel.SPEED_SLOW, self.right_ankle)
utime.sleep_ms(50)
self.servos.angle(MIN, ServoJewel.SPEED_SLOW, self.right_ankle)
utime.sleep_ms(50)
self.undo_lean_to_left(ServoJewel.SPEED_SLOW)
开发者ID:Fri3dCamp,项目名称:badge,代码行数:10,代码来源:robot.py
示例20: say_hello_right
def say_hello_right(self):
self.lean_to_right(ServoJewel.SPEED_SLOW)
for i in range(0, 3):
self.servos.step_angle(120, ServoJewel.SPEED_SLOW, self.left_ankle)
utime.sleep_ms(50)
self.servos.step_angle(60, ServoJewel.SPEED_SLOW, self.left_ankle)
utime.sleep_ms(50)
self.undo_lean_to_right(ServoJewel.SPEED_SLOW)
开发者ID:jantje,项目名称:badge,代码行数:10,代码来源:robot.py
注:本文中的utime.sleep_ms函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论