本文整理汇总了Python中curio.sleep方法的典型用法代码示例。如果您正苦于以下问题:Python curio.sleep方法的具体用法?Python curio.sleep怎么用?Python curio.sleep使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类curio
的用法示例。
在下文中一共展示了curio.sleep方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: import curio [as 别名]
# 或者: from curio import sleep [as 别名]
def run(self):
self.message_info("Running")
colors = cycle([Color.red, Color.purple, Color.yellow, Color.blue, Color.white])
snd = DuploSpeaker.sounds
sounds = cycle([snd.brake, snd.station, snd.water, snd.horn, snd.steam])
self.message_info('Please move the train to start the program')
while not self.go:
await self.led.set_color(next(colors))
await sleep(0.3)
for i in range(5):
await self.led.set_color(next(colors)) # Cycle through the colors
#await self.speaker.play_sound(next(sounds)) # cycle through the sounds
tgt_speed = 20 + i*15 # Keep increasing the speed
await self.motor.ramp_speed(tgt_speed, 2000)
self.message_info(f"Set speed to {i}")
await sleep(3)
self.message_info("Done")
示例2: run
# 需要导入模块: import curio [as 别名]
# 或者: from curio import sleep [as 别名]
def run(self):
self.message_info("Running")
self.keep_running = True
brightness = 0
delta = 10
while self.keep_running:
# change the brightness up and down between -100 and 100
brightness += delta
if brightness >= 100:
delta = -10
elif brightness <= -100:
delta = 10
self.message_info("Brightness: {}".format(brightness))
await self.light.set_brightness(brightness)
await sleep(1)
示例3: run
# 需要导入模块: import curio [as 别名]
# 或者: from curio import sleep [as 别名]
def run(self):
self.message_info("Running")
self.motor_speed = 0
self.keep_running = True
self.sensor_change = False
self.go = False
# Blink the color from purple and yellow
colors = cycle([Color.purple, Color.yellow])
while not self.go: # Wait until the hub button is pushed
await self.train_led.set_color(next(colors))
await sleep(1)
colors = cycle([Color.green, Color.orange])
# Ready to go, let's change the color to green!
while self.keep_running:
if self.sensor_change:
await self.train_led.set_color(next(colors))
await self.motor.ramp_speed(self.motor_speed, 900) # Ramp to new speed in 0.9 seconds
self.sensor_change = False
await sleep(1)
await self.train_led.set_color(next(colors))
else:
await sleep(1)
示例4: send_message
# 需要导入模块: import curio [as 别名]
# 或者: from curio import sleep [as 别名]
def send_message(self, msg_name, msg_bytes, peripheral=None):
"""Insert a message to the hub into the queue(:func:`bricknil.hub.Hub.message_queue`) connected to our BLE
interface
"""
while not self.tx: # Need to make sure we have a handle to the uart
await sleep(1)
await self.message_queue.put((msg_name, self, msg_bytes))
if self.web_queue_out and peripheral:
cls_name = peripheral.__class__.__name__
await self.web_message.send(peripheral, msg_name)
#await self.web_queue_out.put( f'{self.name}|{cls_name}|{peripheral.name}|{peripheral.port}|{msg_name}\r\n'.encode('utf-8') )
示例5: send_message
# 需要导入模块: import curio [as 别名]
# 或者: from curio import sleep [as 别名]
def send_message(self, msg, msg_bytes):
""" Send outgoing message to BLEventQ """
while not self.message_handler:
await sleep(1)
await self.message_handler(msg, msg_bytes, peripheral=self)
示例6: run
# 需要导入模块: import curio [as 别名]
# 或者: from curio import sleep [as 别名]
def run(self):
self.message_info("Running")
self.motor_speed = 0
self.go = False
slow = 40
fast = 70
# Blink the color from purple and yellow
colors = cycle([Color.purple, Color.yellow])
while not self.go: # Wait until the hub button is pushed
await self.train_led.set_color(next(colors))
await sleep(1)
colors = cycle([Color.green, Color.orange])
# Ready to go, let's change the color to green!
await self.motor.ramp_speed(fast, 2000)
self.slow = False
while self.go:
#speed = randint(30,30)
#await self.motor.ramp_speed(speed, 2000)
await self.train_led.set_color(next(colors))
if self.slow:
await self.motor.ramp_speed(slow, 2000)
await self.train_led.set_color(Color.red)
while self.slow:
await sleep(1)
await self.motor.ramp_speed(fast, 2000)
await sleep(1)
示例7: run
# 需要导入模块: import curio [as 别名]
# 或者: from curio import sleep [as 别名]
def run(self):
self.message_info("Running")
await sleep(20) # Give it enough time to gather data
self.message_info("Done")
self.message_info(self.port_info)
示例8: run
# 需要导入模块: import curio [as 别名]
# 或者: from curio import sleep [as 别名]
def run(self):
self.message("Running")
# Set the robot LED to green to show we're ready
await self.led.set_color(Color.green)
await sleep(2)
while True:
await self.led.set_color(Color.blue)
await self.motor.ramp_speed(50, 2000)
await sleep(3)
await self.led.set_color(Color.white)
await self.motor.ramp_speed(-50, 2000)
await sleep(3)
示例9: run
# 需要导入模块: import curio [as 别名]
# 或者: from curio import sleep [as 别名]
def run(self):
self.message_info("Running")
await self.front_drive.set_speed(-100)
await self.rear_drive.set_speed(-100)
await sleep(20) # Give it enough time to gather data
示例10: run
# 需要导入模块: import curio [as 别名]
# 或者: from curio import sleep [as 别名]
def run(self):
self.message_info("Running")
await sleep(20) # Give it enough time to gather data
示例11: run
# 需要导入模块: import curio [as 别名]
# 或者: from curio import sleep [as 别名]
def run(self):
self.message("Running")
# Set the robot LED to green to show we're ready
await self.led.set_color(Color.green)
await sleep(2)
# The powered on position becomes the 12 o'clock reference point
for i in range(5):
# Turn to 11 o'clock position
await self.led.set_color(Color.blue)
await self.motor.set_pos(-30, speed=50)
await sleep(2)
await self.led.set_color(Color.red)
# Turn to 1 o'clock position
await self.motor.set_pos(30, speed=30)
await sleep(2)
await self.led.set_color(Color.yellow)
# Turn to 3 o'clock position
await self.motor.set_pos(90, speed=20)
await sleep(2)
# Rotate a random amount of degrees from 1 to 180
await self.led.set_color(Color.purple)
await self.motor.rotate(randint(1,180), speed=10)
await sleep(3)
# Then reset to 12 o'clock position
await self.led.set_color(Color.green)
await self.motor.set_pos(0)
await sleep(2)
示例12: run
# 需要导入模块: import curio [as 别名]
# 或者: from curio import sleep [as 别名]
def run(self):
self.message('Running')
# Set the remote LED to green to show we're ready
await self.led.set_color(Color.green)
while True:
await sleep(10) # Keep the remote running
示例13: run
# 需要导入模块: import curio [as 别名]
# 或者: from curio import sleep [as 别名]
def run(self):
self.message_info("Running")
await self.motor.ramp_speed(50,3000)
await sleep(60)
for i in range(10,100,10):
self.message_info(f'ramping speed {i}')
await self.motor.ramp_speed(i, 900) # Ramp to new speed in 0.9 seconds
await sleep(3)
for i in range(100,10,-10):
self.message_info(f'ramping down speed {i}')
await self.motor.ramp_speed(i, 900) # Ramp to new speed in 0.9 seconds
await sleep(3)
示例14: _wait_send_message
# 需要导入模块: import curio [as 别名]
# 或者: from curio import sleep [as 别名]
def _wait_send_message(self, mock_call, msg):
print("in mock")
while not mock_call.call_args:
await sleep(0.01)
while not msg in mock_call.call_args[0][0]:
print(mock_call.call_args)
await sleep(0.01)
示例15: _emit_control
# 需要导入模块: import curio [as 别名]
# 或者: from curio import sleep [as 别名]
def _emit_control(self, data, hub, hub_stop_evt, ble, sensor):
async def dummy():
pass
system = await spawn(bricknil.bricknil._run_all(ble, dummy))
while not hub.peripheral_queue:
await sleep(0.1)
#await sleep(3)
port = data.draw(st.integers(0,254))
await hub.peripheral_queue.put( ('attach', (port, sensor.sensor_name)) )
# Now, make sure the sensor sent an activate updates message
if sensor.sensor_name == "Button":
await self._wait_send_message(sensor.send_message, 'Activate button')
else:
await self._wait_send_message(sensor.send_message, 'Activate SENSOR')
# Need to generate a value on the port
# if False:
msg = []
if len(sensor.capabilities) == 1:
# Handle single capability
for cap in sensor.capabilities:
n_datasets, byte_count = sensor.datasets[cap][0:2]
for i in range(n_datasets):
for b in range(byte_count):
msg.append(data.draw(st.integers(0,255)))
msg = bytearray(msg)
await hub.peripheral_queue.put( ('value_change', (port, msg)))
elif len(sensor.capabilities) > 1:
modes = 1
msg.append(modes)
for cap_i, cap in enumerate(sensor.capabilities):
if modes & (1<<cap_i):
n_datasets, byte_count = sensor.datasets[cap][0:2]
for i in range(n_datasets):
for b in range(byte_count):
msg.append(data.draw(st.integers(0,255)))
msg = bytearray(msg)
await hub.peripheral_queue.put( ('value_change', (port, msg)))
await hub_stop_evt.set()
await system.join()