Exemplo n.º 1
0
from rstem import led_matrix, speaker
import time
import os

led_matrix.init_grid(
)  # This sets up the led matrix. It must be run before displaying anything.
led_matrix.erase(
)  # This clears the led matrix display incase anything is currently being displayed.

# 1. Create sprite variables of a face with mouth open and closed from .spr files.
mouth_closed = led_matrix.LEDSprite(os.path.abspath("mouth_closed.spr"))
mouth_open = led_matrix.LEDSprite(os.path.abspath("mouth_open.spr"))

# 2. Make the RaspberryPi say "Hello World"
speaker.say("Hello World")

# 3. Create a while loop that keeps looping until the Raspberry Pi has stopped talking.
while speaker.is_talking():
    # 4. Clear the led matrix
    led_matrix.erase()

    # 5. Draw the face with its mouth open
    led_matrix.sprite(mouth_open)

    # 6. Show the new face on the display and add a delay
    led_matrix.show()
    time.sleep(.1)

    # 7. Clear the led matrix of the previous face
    led_matrix.erase()
Exemplo n.º 2
0
UP = 25
DOWN = 24
LEFT = 23
RIGHT = 18
SELECT = 22
START = 27
A = 4
B = 17
"""Shape names as described in U{http://en.wikipedia.org/wiki/Tetris}"""
SHAPES = "IJLOSTZ"
shape_sprites = {}
for shape in SHAPES:
    # store LEDSprite of tetris piece
    sprite = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                          "tetris_sprites", shape + ".spr")
    shape_sprites[shape] = led_matrix.LEDSprite(sprite)

# notify of progress
print("P80")
sys.stdout.flush()


def valid_shape(shape):
    """
    @returns: True if given shape is a valid tetris shape
    """
    return shape in SHAPES and len(shape) == 1


class Sidebar(object):
    """Represents the side bar to the right of the stack. Will show score and next piece"""
Exemplo n.º 3
0
# notify of progress
print("P70")
sys.stdout.flush()

title = led_matrix.LEDText("STACK-EM", font_name="large")

# notify of progress
print("P80")
sys.stdout.flush()

# create intro title (a vertical display of "STACKEM")
title = led_matrix.LEDText("M").rotate(90)
for character in reversed("STACKE"):
    # append a 1 pixel wide (high) spacing
    title.append(led_matrix.LEDSprite(width=1, height=title.height))
    # append next character
    title.append(led_matrix.LEDText(character).rotate(90))
# rotate title up
title.rotate(-90)

# notify of progress
print("P100")
sys.stdout.flush()

# State Machine ==================

# notify menu we are ready for the led matrix
print("READY")
sys.stdout.flush()
Exemplo n.º 4
0
# set up accelerometer
accel.init(1)

# set up GPIO
GPIO.setmode(GPIO.BCM)

# notify of progress
print("P60")
sys.stdout.flush()

# set up dice sprites
dice = []
for value in range(1,7):
    sprite = os.path.join(os.path.dirname(os.path.abspath(__file__)), "dice_sprites", str(value) + ".spr")
    dice.append(led_matrix.LEDSprite(sprite))

# notify of progress
print("P90")
sys.stdout.flush()
    
# set up buttons
UP = 25
DOWN = 24
LEFT = 23
RIGHT = 18
A = 4
B = 17
START = 27
SELECT = 22
import os

led_matrix.init_grid(
)  # This sets up the led matrix. It must be run before displaying anything.
led_matrix.erase(
)  # This clears the led matrix display incase anything is currently being displayed.

# Initialize a button at GPIO port 4 (the A button)
my_button = button.Button(4)

# Create sprite variables of the frames appended to the list
frames = []  # originally create an empty list
for i in range(1, 8):  # a for loop that counts from 1 to 7
    # add mani.spr sprite to frame list, (where i is our current number 1-7)
    frames.append(
        led_matrix.LEDSprite(os.path.abspath("man" + str(i) + ".spr")))

# Create a while loop that loops forever.
while True:

    # Loop through each of the frames
    for current_sprite in frames:
        # Erase display to clear previous frame
        led_matrix.erase()

        # If the button is pressed we want to display the sprite jumping.
        if my_button.is_pressed():
            # draw the sprite up 2 pixels to simulate it jumping
            led_matrix.sprite(current_sprite, (0, 2))
        else:
            # if not jumping draw the sprite at the origin
from rstem import led_matrix
import time
import os

led_matrix.init_grid()  # This sets up the led matrix. It must be run before displaying anything.
led_matrix.erase()      # This clears the led matrix display incase anything is currently being displayed.


# Create sprite variables of the frames of a guy walking animation.
man1 = led_matrix.LEDSprite(os.path.abspath("man1.spr"))
man2 = led_matrix.LEDSprite(os.path.abspath("man2.spr"))
man3 = led_matrix.LEDSprite(os.path.abspath("man3.spr"))
man4 = led_matrix.LEDSprite(os.path.abspath("man4.spr"))
man5 = led_matrix.LEDSprite(os.path.abspath("man5.spr"))
man6 = led_matrix.LEDSprite(os.path.abspath("man6.spr"))
man7 = led_matrix.LEDSprite(os.path.abspath("man7.spr"))

# Put the sprite in a list to make it easy to loop through them.
frames = [man1, man2, man3, man4, man5, man6, man7]

# Create a while loop that loops forever.
while True:

    # Loop through each of the frames
    for current_sprite in frames:
        # Erase display to clear previous frame
        led_matrix.erase()
        
        # Draw current display
        led_matrix.sprite(current_sprite)
        
from rstem import led_matrix, button
import time
import os

led_matrix.init_grid()  # This sets up the led matrix. It must be run before displaying anything.
led_matrix.erase()      # This clears the led matrix display incase anything is currently being displayed.

# Create sprite variables of the frames appended to the list
frames = []   # originally create an empty list
for i in range(1,8):  # a for loop that counts from 1 to 7
    # add mani.spr sprite to frame list, (where i is our current number 1-7)
    frames.append(led_matrix.LEDSprite(os.path.abspath("man" + str(i) + ".spr")))
    
# Create a variable that indicates if the sprite is moving left or right.
moving_right = True  # if True it is moving right, if False it is moving left

# Create an x variable that indicates the current x position the sprite is on the display
x = 0  # initially we want our x value to be 0

# Create a while loop that loops forever.
while True:

    # Loop through each of the frames
    for current_sprite in frames:
        # Erase display to clear previous sprite
        led_matrix.erase()
        
        if moving_right:
            # show the sprite as normal (facing right)
            led_matrix.sprite(current_sprite, (x,0))
        else: