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


Python microbit.sleep函数代码示例

本文整理汇总了Python中microbit.sleep函数的典型用法代码示例。如果您正苦于以下问题:Python sleep函数的具体用法?Python sleep怎么用?Python sleep使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: receive

def receive():
    """Starts a receiver program"""
    radio.on()
    channel_idx = 0

    while True:
        # Handle the display switching
        # A for prev channel, B for next channel
        channel_selector = button_incdec()
        if channel_selector != 0:
            # Switch the channel
            channel_idx = (channel_idx + channel_selector) % MAX_DISPLAY_IDX
            radio.config(channel=BASE_CHANNEL + channel_idx, length=251)
            radio.on()
 
            # Give the user some feedback
            display.show(str(channel_idx))
            sleep(750)
            display.clear()
            
        msg = radio.receive()
        if msg:
            # TODO: validate that we have received a valid frame
            try:
                display.show(eval(msg))
            except Exception as e:
		display.show(Image.SAD)
                print(repr(e))
开发者ID:kjagiello,项目名称:microbit-sandbox,代码行数:28,代码来源:external_display.py

示例2: test_sleep

def test_sleep():
    # check that sleep works ok with speech because they both use low-level timers
    # (this is really a test of the audio module)
    print('Testing sleep with speech')
    microbit.sleep(1)
    speech.say('hello world')
    microbit.sleep(1)
开发者ID:carlosperate,项目名称:micropython,代码行数:7,代码来源:test_speech.py

示例3: main

def main():
    x = 0
    y = 0
    tick = 0
    while True:
        tick += 1
        if tick == 4:
            # walk around, with collision detection
            tick = 0
            if ac.get_x() > 200 and get_maze(x + 1, y) == 0:
                x += 1
            elif ac.get_x() < -200 and get_maze(x - 1, y) == 0:
                x -= 1
            elif ac.get_y() > 200 and get_maze(x, y + 1) == 0:
                y += 1
            elif ac.get_y() < -200 and get_maze(x, y - 1) == 0:
                y -= 1
            x = min(15, max(0, x))
            y = min(15, max(0, y))

        # draw the maze
        draw(x, y, tick)


        microbit.sleep(50)
开发者ID:AvdN,项目名称:micropython,代码行数:25,代码来源:maze.py

示例4: move

    def move(self):
        #work out where the new segment of the snake will be
        newSegment = [self.tail[0][0], self.tail[0][1]]
        if self.direction == self.UP:
            newSegment[1] -= 1
        elif self.direction == self.DOWN:
            newSegment[1] += 1
        elif self.direction == self.LEFT:
            newSegment[0] -= 1
        elif self.direction == self.RIGHT:
            newSegment[0] += 1

        if self.checkCollision(newSegment[0], newSegment[1]):
            #game over
            snakehead = self.tail[0]
            for flashHead in range(0,5):
                microbit.display.set_pixel(snakehead[0], snakehead[1], self.SNAKEBRIGHTNESS)
                microbit.sleep(200)
                microbit.display.set_pixel(snakehead[0], snakehead[1], 0)
                microbit.sleep(200)
            
            return False
            
        else:
            self.addSegment(newSegment[0], newSegment[1])

            #has the snake eaten the apple?
            if newSegment[0] == self.apple[0] and newSegment[1] == self.apple[1]:
                self.length += 1
                self.score += 10
                self.createApple()

            return True
开发者ID:martinohanlon,项目名称:microbit-micropython,代码行数:33,代码来源:snakebit.py

示例5: detect_motion

def detect_motion():
    x = microbit.io.P0.get_digital_value()
    y = x
    while x == y:
        x = y
        y = microbit.io.P0.get_digital_value()
        microbit.sleep(10)
开发者ID:jrmhaig,项目名称:microbit_playground,代码行数:7,代码来源:tardis_2.py

示例6: play_game

def play_game(delay=100, accelerometer_sensitivity=1/300):
    """Enter game main event loop."""
    x, y = 2, 2   # Pixel coordinates, starting in middle of display
    winner = None
    while winner is None:
        if button_a.is_pressed():
            x = x + 1
            play('A:1')
        if button_b.is_pressed():
            x = x - 1
            play('B:1')

        if x > 4:
            winner = 'A'
        elif x < 0:
            winner = 'B'
        else:
            # No winner - continue
            set_pixel(x, y)

        # Change row based on accelerometer angle
        delta = accelerometer.get_y() * accelerometer_sensitivity
        y = max(0, min(4, int(y + delta)))

        sleep(delay)

    return winner
开发者ID:paulegan,项目名称:microbit,代码行数:27,代码来源:pong.py

示例7: updown

def updown():
    for p in range(10, 1000, 10):
        pitch(p, wait=False)
        sleep(10)
    for p in range(1000, 10, -10):
        pitch(p, wait=False)
        sleep(10)
开发者ID:paulegan,项目名称:microbit,代码行数:7,代码来源:pitch.py

示例8: animate_sin

def animate_sin(operation):
    brightness_max = 9
    half_brightness_max = brightness_max / 2
    two_pi = math.pi * 2

    origo_x, origo_y = 2, 2

    max_distance = hypot(origo_x, origo_y)
    double_max_distance = max_distance * 2
    offset = 0
    last_t = microbit.running_time()

    while True:
        for x in range(0, 5):
            dist_x = x - origo_x
            for y in range(0, 5):
                dist_y = y - origo_y

                distance = (math.fabs(hypot(dist_x, dist_y)) /
                            double_max_distance)
                distance = (distance + (offset / operation)) % 1

                sin = math.sin(distance * two_pi - math.pi)

                value = round(sin * half_brightness_max + half_brightness_max)

                microbit.display.set_pixel(x, y, value)

        t_now = microbit.running_time()
        delta_t = t_now - last_t
        offset += delta_t * 0.001
        last_t = t_now
        microbit.sleep(10)
开发者ID:jocke-l,项目名称:microbit-simulator,代码行数:33,代码来源:test_display.py

示例9: startGame

    def startGame(self):
        microbit.display.clear()
        self.ox=0
        
       
        self.score = 0
        
        self.bstates0=self.getbuttons()
        
        
        
        playing = True
        
        samples = 0
        self.ctr=0
        self.move=0
        while(playing):
            #keep looping around, if the button is pressed, move the snake immediately, 
            #otherwise move it when the sample time is reached
            self.ctr+=1
            
            
            
            microbit.sleep(self.SAMPLETIME)
            self.updatebuttons()
            moved=0
            if self.bchange[0]==1:
                moved=1
                self.ox+=1
            elif self.bchange[1]==1:
                moved=1
                self.ox-=1

            samples = samples + 1
            if moved or samples >= self.samplespermove:
                self.move+=1
                if self.move%40 ==0:
                    self.samplespermove-=1
                if self.move %50 ==0:
                    self.w-=1
                if self.w<2:
                    self.w=2
                self.score+=10
                self.drawBoard()
                
                #check collision
                left,right=self.board[-1]
                x=2-self.ox
                if x<=left or x>=right:
                    break   
                self.moveBoard()
                samples = 0
            self.drawPlayer()
            #if self.ox<0 and self.ctr>100:
               # break
        #microbit.display.scroll(str(self.ox))
        
        microbit.display.scroll("Score = " + str(self.score), 100)
        microbit.display.clear()
开发者ID:darrenjw,项目名称:djwhacks,代码行数:59,代码来源:stay-on-the-road.py

示例10: start_countdown

def start_countdown(count=3):
    """Play a countdown animation for the specified number of seconds."""
    for i in range(count, 0, -1):
        display.show(str(i))
        play('C:1')
        sleep(1000)
    play('A:3')
    display.clear()
开发者ID:paulegan,项目名称:microbit,代码行数:8,代码来源:pong.py

示例11: forever_four_buttons

def forever_four_buttons():
    while True:
        four_buttons()

        microbit.sleep(10)

        # fade all pixels by one brightness level
        fade_display()
开发者ID:tomviner,项目名称:micro-bit-examples,代码行数:8,代码来源:four_buttons.py

示例12: animate

def animate(image, delay, *, stride=5, start=-5, wait=True, loop=False):
    # TODO: full impl.
    for frame in image:
        for y in range(frame.height()):
            for x in range(frame.width()):
                glow = frame.get_pixel(x, y)
                set_pixel(x, y, glow)
        _microbit.sleep(delay)
开发者ID:tlynn,项目名称:bitlike,代码行数:8,代码来源:__init__.py

示例13: start

def start():
    for i in range(5):
        sleep(500)
        if not (button_a.is_pressed() and button_b.is_pressed()):
            return

    location = random.choice(LOCATIONS)
    radio.send(location)
    play(location)
开发者ID:MoMaT,项目名称:slides,代码行数:9,代码来源:spyfall.py

示例14: led_dance

def led_dance(delay):
    dots = [ [0]*5, [0]*5, [0]*5, [0]*5, [0]*5 ]
    while True:
        dots[microbit.random(5)][microbit.random(5)] = 8
        for i in range(5):
            for j in range(5):
                microbit.display.set_pixel(i, j, dots[i][j])
                dots[i][j] = max(dots[i][j] - 1, 0)
        microbit.sleep(delay)
开发者ID:hjwp,项目名称:micropython,代码行数:9,代码来源:led_dance.py

示例15: test_timing

def test_timing():
    # test that speech takes the correct amount of time over many runs
    print('Testing timing of say function')
    for i in range(5):
        start = microbit.running_time()
        speech.say('hello world')
        microbit.sleep(1)
        stop = microbit.running_time()
        assert 800 < stop - start < 815
开发者ID:carlosperate,项目名称:micropython,代码行数:9,代码来源:test_speech.py


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