def get_pressed_button():
    if picounicorn.is_pressed(picounicorn.BUTTON_A):
        return True, picounicorn.BUTTON_A
    if picounicorn.is_pressed(picounicorn.BUTTON_B):
        return True, picounicorn.BUTTON_B
    if picounicorn.is_pressed(picounicorn.BUTTON_X):
        return True, picounicorn.BUTTON_X
    if picounicorn.is_pressed(picounicorn.BUTTON_Y):
        return True, picounicorn.BUTTON_Y
    return False, False
Beispiel #2
0
def pomocycle():

    # Set up our variables
    r = 255
    g = 0
    column = 15
    row = 6
    phase = "work"
    multiplier = 134

    # Start counting down
    while not (picounicorn.is_pressed(picounicorn.BUTTON_Y)):

        # Illuminate every LED on the board
        for x in range(16):
            for y in range(7):
                picounicorn.set_pixel(x, y, r, g, 0)

        # Extinguish LEDs one by one
        while row > -1:
            while column > -1:
                for x in range(multiplier):
                    if not (picounicorn.is_pressed(picounicorn.BUTTON_Y)):
                        utime.sleep(0.1)
                    else:
                        break
                picounicorn.set_pixel(column, row, 0, 0, 0)
                column -= 1
            column = 15
            row -= 1
        row = 6

        # No more LEDs? Switch from work to rest and vice versa
        if phase == "work":
            phase = "rest"
            multiplier = 27
            r = 0
            g = 255
        elif phase == "rest":
            phase = "work"
            multiplier = 134
            r = 255
            g = 0
        pass

    # Clear the display
    for x in range(16):
        for y in range(7):
            picounicorn.set_pixel(x, y, 0, 0, 0)
Beispiel #3
0
def draw(w, h, t, sr=0, sc=0, clear=False):
    for row_w in range(sr, w):
        for col_h in range(sc, h):
            if clear:
                x, y, z = 0, 0, 0
            else:
                x, y, z = _rgb_randomiser()
            picounicorn.set_pixel(row_w, col_h, x, y, z)
            sleep(t)

            if picounicorn.is_pressed(picounicorn.BUTTON_B) and not clear:
                sleep(0.5)
                return row_w, col_h

        if sc != 0:  # to make sure all subsequent rows get randomised
            sc = 0

    return 0, 0
Beispiel #4
0
def make_dance(w, h):
    def_t = 0.01
    t = def_t  # default sleep time
    r_num = 0
    row = 0
    col = 0
    while not picounicorn.is_pressed(picounicorn.BUTTON_A):

        row, col = draw(w, h, t, row, col)
        if (row, col) != (0, 0):
            r_num += 1
            if r_num > 4:
                t = def_t
                r_num = 0
            else:
                t = t * 2.5

            print(r_num, t)

    print('Clearing screen')
    draw(w, h, t=0, clear=True)
    sleep(1)
Beispiel #5
0
    if i == 2:
        return p, v, t
    if i == 3:
        return p, q, v
    if i == 4:
        return t, p, v
    if i == 5:
        return v, p, q


width = picounicorn.get_width()
height = picounicorn.get_height()

print("Running!")

while not picounicorn.is_pressed(
        picounicorn.BUTTON_A):  # Wait for Button A to be pressed
    # Scroll red across
    for x in range(width):
        for y in range(height):
            r, g, b = [int(c * 255) for c in hsv_to_rgb(x / width, 1.0, 1.0)]
            picounicorn.set_pixel(x, y, r, g, b)
        time.sleep_ms(50)

    # Clear the display
    for x in range(width):
        for y in range(height):
            picounicorn.set_pixel(x, y, 0, 0, 0)
        time.sleep_ms(50)

for x in range(width):
    for y in range(height):
Beispiel #6
0
        return q, v, p
    if i == 2:
        return p, v, t
    if i == 3:
        return p, q, v
    if i == 4:
        return t, p, v
    if i == 5:
        return v, p, q


width = picounicorn.get_width()  #16
height = picounicorn.get_height()  #7

hue = 0.0
while not picounicorn.is_pressed(picounicorn.BUTTON_B):
    while picounicorn.is_pressed(picounicorn.BUTTON_A):
        print(hue)
        r, g, b = [int(c * 255) for c in hsv_to_rgb(hue, 1.0, 1.0)]
        for x in range(width):
            for y in range(height):
                picounicorn.set_pixel(x, y, r, g, b)
        hue += 0.01
        if hue > 1.1:
            hue = 0.0
        time.sleep_ms(50)

# Clear the display
for x in range(width):
    for y in range(height):
        picounicorn.set_pixel(x, y, 0, 0, 0)
Beispiel #7
0
while True:
    ballx, bally, dirH, dirV, scoreAB, scoreXY, ballcolours, startdirH = ballposition(
        ballx, bally, dirH, dirV, scoreAB, scoreXY, ballcolours, startdirH)
    if scoreAB >= 5 or scoreXY >= 5:
        if scoreAB >= 5:
            winningcolour = "A"
        else:
            winningcolour = "Y"
        cleardisplay()
        currentdisplaymap = updatedisplay(generatemessage(winningcolour))
        for i in range(w * 3):
            currentdisplaymap = updatedisplay(scrolldisplay(currentdisplaymap))
            utime.sleep(0.1)
        break
    else:
        if picounicorn.is_pressed(picounicorn.BUTTON_A):
            if onlistAB[0] != 0:
                onlistAB.insert(0, onlistAB[0] - 1)
                onlistAB = onlistAB[:-1]
        elif picounicorn.is_pressed(picounicorn.BUTTON_B):
            if onlistAB[-1] != 6:
                onlistAB.insert(len(onlistAB), onlistAB[-1] + 1)
                onlistAB = onlistAB[1:]
        if picounicorn.is_pressed(picounicorn.BUTTON_X):
            if onlistXY[0] != 0:
                onlistXY.insert(0, onlistXY[0] - 1)
                onlistXY = onlistXY[:-1]
        elif picounicorn.is_pressed(picounicorn.BUTTON_Y):
            if onlistXY[-1] != 6:
                onlistXY.insert(len(onlistXY), onlistXY[-1] + 1)
                onlistXY = onlistXY[1:]
Beispiel #8
0
                    else:
                        break
                picounicorn.set_pixel(column, row, 0, 0, 0)
                column -= 1
            column = 15
            row -= 1
        row = 6

        # No more LEDs? Switch from work to rest and vice versa
        if phase == "work":
            phase = "rest"
            multiplier = 27
            r = 0
            g = 255
        elif phase == "rest":
            phase = "work"
            multiplier = 134
            r = 255
            g = 0
        pass

    # Clear the display
    for x in range(16):
        for y in range(7):
            picounicorn.set_pixel(x, y, 0, 0, 0)


while True:
    while picounicorn.is_pressed(picounicorn.BUTTON_X):
        pomocycle()