Actions

Microbit Code01:LEDs Animation

From /oooooooooo.io/

from microbit import *

# LED Animation: 1 blank LED cycles through the microbit LED matrix 

# Example of LED control strings
# first row LEDs to 100%, remaining to 0%
display.show(Image('99999:00000:00000:00000:00000'))
sleep(2000)
# 1st led from 1st row & last led from last row
display.show(Image('90000:00000:00000:00000:00009'))
sleep(2000)
# decreasing intensity across the rows of LEDs 
display.show(Image('99999:77777:55555:33333:11111'))
sleep(2000)

def matrix2Image(l_of_l):
    # desc: converts 5x5 matrix (list of lists) to Image string
    # input: list of lists of ints
    # [[9, 9, 9, 9, 9], [9, 9, 9, 9, 9], [9, 9, 9, 9, 9], [9, 9, 9, 9, 9], [9, 9, 9, 9, 0]]
    # each list corresponding to a LED-row_list
    # each int corresponding to LED
    # values: 0 to 9 determine intensity
    # output: '99999:99999:99999:99999:99990'
    img_str = ""
    for row_list in l_of_l:
        row_list = [str(i) for i in row_list]
        row_str = "".join(row_list)
        img_str += row_str + ":"
    return img_str

matrix = [[9] * 5 for i in range(5)] # list of list: matrix of LEDs
matrix_str = matrix2Image(matrix)
display.show(Image(matrix_str))

sleep(200)

# Animation loop
i = 0
while True:
    i = i % len(matrix[0])
    # i fow each row will be zero
    for row in matrix:
        row[i] = 0
        matrix_str = matrix2Image(matrix)
        display.show(Image(matrix_str))
        sleep(15)
        row[i] = 9
        matrix_str = matrix2Image(matrix)
        display.show(Image(matrix_str))
        sleep(10)
    i += 1

HackPact 2019

SectionHackPact +
Date
"Date" is a type and predefined property provided by Semantic MediaWiki to represent date values.
2019 +