Пример #1
0
circuitpython-badge/minimal_examples/timers.py

This is an example that demonstrates how you can move towards more complex programs with
multiple things happening at once (in truth the microcontroller can only do one thing at a
time and we are still working with a procedural program). The example takes time stamps so we
can test if x amount of time has passed, and if so then make something happen!

Aidan T 2018
'''

import badge
import time

badge.init()

p = badge.Pix() # initialise the led matrix

t1 = time.time() # sample the current time since you powered on in seconds
t2 = time.time() # another time sample!

interval1 = 1 # to test for a 1 second interval
interval2 = 3 # to test for a 3 second interval

# let's make some matrix functions to play with

l = 0
r = 0

def flashleftbar():
    global l
Пример #2
0
import badge
import random

texts = [
    "Hello world!",
    "Kill all humans!",
    "Resistance is futile.",
    "You will be assimilated.",
]

badge.init()
text = badge.Pix.from_text("Kill all humans!")
screen = badge.Pix()
for y in range(11):
    for x in range(14):
        screen.pixel(x, y, int(abs(x-7 + y-3.5) * 2))
tx = 14
badge.show(screen)
badge.brightness(0)
screen.box(0, 0, 2, 14, 7)
while True:
    screen.blit(text, tx, 3)
    tx -= 1
    if tx < -text.width:
        tx = 14
        text = badge.Pix.from_text(random.choice(texts))
    badge.show(screen)
    badge.tick(1/12)
Пример #3
0
import badge
import gc

badge.init()

# Please note, Sylons are distinct from robots in popular sci-fi series

sylon_going_right = badge.Pix(6, 2)
for row in (0, 1):
    sylon_going_right.pixel(5, row, 16)
    sylon_going_right.pixel(4, row, 16)
    sylon_going_right.pixel(3, row, 12)
    sylon_going_right.pixel(2, row, 8)
    sylon_going_right.pixel(1, row, 4)
    sylon_going_right.pixel(0, row, 2)

sylon_going_left = badge.Pix(6, 2)
for row in (0, 1):
    sylon_going_left.pixel(0, row, 16)
    sylon_going_left.pixel(1, row, 16)
    sylon_going_left.pixel(2, row, 12)
    sylon_going_left.pixel(3, row, 8)
    sylon_going_left.pixel(4, row, 4)
    sylon_going_left.pixel(5, row, 2)

ZOOP = [
    sylon_going_right,
    sylon_going_left,
]

screen = badge.Pix()
Пример #4
0
'''
circuitpython-badge/minimal_examples/randompix.py

A selection of random infested animations

Aidan T 2018
'''

import badge
from random import randint

badge.init()

p = badge.Pix()


# randomfuzz - Generate n random positioned/brightness pixels
def randomfuzz(density):
    # clear the screen
    for x in range(p.width):
        for y in range(p.height):
            p.pixel(x, y, 0)

    badge.show(p)

    # Generate (n) randomly positioned pixels
    for i in range(density):
        rx = randint(0, p.width)
        ry = randint(0, p.height)
        rb = randint(0, 16)
        p.pixel(rx, ry, rb)