コード例 #1
0
ファイル: Part4.py プロジェクト: SkyFawkes/microbit-fireworks
def fade(time):
    for x in range(0, 5):
        for y in range(0, 5):
            b = display.get_pixel(x, y)
            if b > 0:
                display.set_pixel(x, y, b - 1)
            sleep(time)
コード例 #2
0
ファイル: tilty.py プロジェクト: blogmywiki/tilty
def count_lit_pixels():
    pixel_count = 0
    for xx in range(5):
        for yy in range(5):
            if display.get_pixel(xx, yy) != 0:
                pixel_count += 1
    return pixel_count
コード例 #3
0
def count_down(delay):
    """Count down and show progress"""
    on_image = Image('99999:99999:99999:99999:99999')
    display.show(on_image)

    for y_coord in range(5):
        for x_coord in range(5):
            wait = delay
            while wait >= 300:
                sleep(300)
                wait -= 300
                if abandon_talk() is True:
                    return

                # Flash the last row, so making it clear that
                # the talk is coming to an end

                if y_coord == 4:
                    for i in range(x_coord, 5):
                        brightness = display.get_pixel(i, y_coord)
                        if brightness == 0:
                            brightness = 9
                        else:
                            brightness = 0
                        display.set_pixel(i, y_coord, brightness)

            sleep(wait)
            display.set_pixel(x_coord, y_coord, 0)

    start_up_screen()
    return
コード例 #4
0
def count_lit_pixels():
    pixel_count = 0
    for xx in range (5):
        for yy in range (5):
            if display.get_pixel(xx, yy) != 0:
                pixel_count += 1
    return pixel_count
コード例 #5
0
ファイル: pong.py プロジェクト: tdamdouni/iMicroBit
def fade_display(fade=-3):
    """Loop over every pixel and reduce the brightness by the fade value."""
    for x in range(0, 5):
        for y in range(0, 5):
            current = display.get_pixel(x, y)
            faded = max(0, current + fade)
            display.set_pixel(x, y, faded)
コード例 #6
0
ファイル: altair.py プロジェクト: pdbperks/altair8800
def dataRead():
    global databyte
    datab = ""
    for y in range(3, 5):
        for x in range(1, 5):
            if (display.get_pixel(x, y) > 0):
                datab = datab + "1"
            else:
                datab = datab + "0"
    databyte = datab
コード例 #7
0
ファイル: smooth1.py プロジェクト: rbanffy/fun-with-microbit
"""
LEDs start at random brightnesses and go up or down randomly by one level.
"""
import random

from microbit import display

while True:
    for x in range(5):
        for y in range(5):
            brightness = display.get_pixel(x, y)
            brightness += random.randrange(-1, 2)
            if brightness > 9:
                brightness = 9
            elif brightness < 0:
                brightness = 0
            display.set_pixel(x, y, brightness)
コード例 #8
0
def fade():
    for x in range(5):
        for y in range(5):
            brightness = display.get_pixel(x, y)
            if brightness > 0:
                display.set_pixel(x, y, brightness - 1)
コード例 #9
0
ファイル: altair.py プロジェクト: pdbperks/altair8800
                with open('data.bin', 'wb') as f:
                    f.write((memory))
                display.scroll('saved')
            elif clicks == 4:  #toggle tr acc
                tr ^= True
            elif clicks == 5:  #reload sample program
                for i, d in enumerate(prog):
                    memory[i] = d
                memRead(pc)
            elif clicks == 0:  #no button clear data
                databyte = "00000000"
                dataWrite(databyte)

        else:
            display.set_pixel(row, col,
                              (7 * (display.get_pixel(row, col) < 1)))
            dataRead()

    elif button_b.is_pressed():
        longpress = 0
        clicks = button_a.get_presses()
        clicks = 0
        while button_b.is_pressed():
            sleep(100)
            longpress = longpress + 1
        if longpress > 5:  #options if button down >0.5second
            clicks = button_a.get_presses()
            if clicks == 1:
                memWrite(pc)
                pc = min(pc + 1, 255)
                memRead(pc)
コード例 #10
0
# Name: Fireflies
# Coder: Marco Janssen (twitter @marc0janssen)
# date: 2021-03-30
# version: 1.0.6

from microbit import display, sleep
from random import randint

while True:
    sleep(50)

    brightness = randint(1, 9)
    x = randint(0, 4)
    y = randint(0, 4)
    if display.get_pixel(x, y) == 0:
        display.set_pixel(x, y, brightness)

    for fireflies in range(0, 5):
        x = randint(0, 4)
        y = randint(0, 4)

        brightness = max(display.get_pixel(x, y), 1)
        display.set_pixel(x, y, brightness - 1)
コード例 #11
0
ファイル: life2.py プロジェクト: rbanffy/fun-with-microbit
def fade(how_much=1):
    for x in range(5):
        for y in range(5):
            brightness = display.get_pixel(x, y)
            if brightness >= how_much:
                display.set_pixel(x, y, brightness - how_much)
コード例 #12
0
        lx = max_x

    if ly < -max_y:
        ly = -max_y
    elif ly > max_y:
        ly = max_y

    if lx == 0 and ly == 0:
        dot_brightness = tgt_bright
    else:
        dot_brightness = bubble_bright

    dotx = max_x - lx
    doty = max_y - ly

    background = display.get_pixel(dotx, doty)
    display.set_pixel(dotx, doty, dot_brightness)
    if dot_brightness == tgt_bright:
        display.set_pixel(dotx + 1, doty, dot_brightness)
        display.set_pixel(dotx - 1, doty, dot_brightness)
        display.set_pixel(dotx, doty + 1, dot_brightness)
        display.set_pixel(dotx, doty - 1, dot_brightness)

    sleep(100)

    display.set_pixel(dotx, doty, background)
    if dot_brightness == tgt_bright:
        display.set_pixel(dotx + 1, doty, 0)
        display.set_pixel(dotx - 1, doty, 0)
        display.set_pixel(dotx, doty + 1, 0)
        display.set_pixel(dotx, doty - 1, 0)
コード例 #13
0
ファイル: 03.py プロジェクト: liarazhang/dxkStickIDE
# 循环进行
while True:
    # 读取电位器位置(0-4095)
    pv = poten.value()

    # 根据读数设置LED灯状态
    new_stat = (pv >= 2048)
    if new_stat != is_on:
        is_on = new_stat
        function_map[is_on]()

    # 渐隐效果
    for i in range(5):
        for j in range(5):
            lightness = display.get_pixel(i, j)
            display.set_pixel(i, j, max(0, lightness - 1))

    # 计算并设置点亮像素位置
    pos = int(pv * 25 / 4100)
    pt = pos
    while True:
        display.set_pixel(pt % 5, pt // 5, 9)
        if pt == pos_old:
            break
        elif pt > pos_old:
            pt -= 1
        else:
            pt += 1
    pos_old = pos
コード例 #14
0
ファイル: road_runner.py プロジェクト: garybake/microbake
def swap_led(x, y):
    """ Alternate an LED between light and dark """
    if display.get_pixel(x, y) == 1:
        display.set_pixel(x, y, 4)
    else:
        display.set_pixel(x, y, 1)