def win(): string = "You won! Score: %i" % (score) msg = led_matrix.LEDText(string, font_name='large') for i in range(len(string) * 6 + 15): led_matrix.fill(0) led_matrix.text(msg, (15 - i, 7)) led_matrix.show() sys.exit(0)
def win(): string = "You won! Score: %i" % (score) msg = led_matrix.LEDText(string, font_name='large') for i in range(len(string)*6 + 15): led_matrix.fill(0) led_matrix.text(msg, (15 - i, 7)) led_matrix.show() sys.exit(0)
def lose(): string = "You lost! Score: %i" % (score) msg = led_matrix.LEDText(string, font_name='large') for i in range(len(string) * 6 + 15): led_matrix.fill(0) led_matrix.text(msg, (15 - i, 7)) led_matrix.show() # time.sleep(0.1) sys.exit(0)
def draw(self): led_matrix.line((self.x_pos, 0), (self.x_pos, led_matrix.height() - 1)) # draw the next piece next_piece.draw(pos=(self.x_pos + 3, led_matrix.height() - 5)) # draw the score (aligned nicely) if score < 10: led_matrix.text(str(score), (self.x_pos + 5, 1)) else: led_matrix.text(str(score), (self.x_pos + 1, 1))
def lose(): string = "You lost! Score: %i" % (score) msg = led_matrix.LEDText(string, font_name='large') for i in range(len(string)*6 + 15): led_matrix.fill(0) led_matrix.text(msg, (15 - i, 7)) led_matrix.show() # time.sleep(0.1) sys.exit(0)
def draw(self): led_matrix.line((self.x_pos, 0), (self.x_pos, led_matrix.height()-1)) # draw the next piece next_piece.draw(pos=(self.x_pos + 3, led_matrix.height() - 5)) # draw the score (aligned nicely) if score < 10: led_matrix.text(str(score), (self.x_pos + 5, 1)) else: led_matrix.text(str(score), (self.x_pos + 1, 1))
def lose(): GPIO.cleanup() text = "Game Over!" msg = led_matrix.LEDText(text, font_name="large") for i in range(len(text) * 6 + 15): led_matrix.fill(0) led_matrix.text(msg, (15 - i, 7)) led_matrix.show() time.sleep(0.1) sys.exit(0)
def win(): GPIO.cleanup() text = "You Won in %is" % (int(time.time() - start_time)) msg = led_matrix.LEDText(text, font_name="large") for i in range(len(text) * 6 + 15): led_matrix.fill(0) led_matrix.text(msg, (15 - i, 7)) led_matrix.show() time.sleep(0.1) sys.exit()
def win(): GPIO.cleanup() text = "You Won in %is" % (int(time.time()-start_time)) msg = led_matrix.LEDText(text, font_name="large") for i in range(len(text)*6+15): led_matrix.fill(0) led_matrix.text(msg, (15-i, 7)) led_matrix.show() time.sleep(0.1) sys.exit()
def lose(): GPIO.cleanup() text = "Game Over!" msg = led_matrix.LEDText(text, font_name="large") for i in range(len(text)*6 + 15): led_matrix.fill(0) led_matrix.text(msg, (15 - i,7)) led_matrix.show() time.sleep(0.1) sys.exit(0)
def scroll_text(string): """Scrolls the given text""" msg = led_matrix.LEDText(string, font_name='large') prev_state = state for i in range(len(string)*6 + 15): if state != prev_state: return # leav if state has changed in the middle of scrolling led_matrix.erase() led_matrix.text(msg, (15 - i, 7)) led_matrix.show() time.sleep(0.1)
def __init__(self, menu_items, show_loading=False): items = [] # convert titles for i, item in enumerate(menu_items): if show_loading: led_matrix.erase() led_matrix.text(str(len(menu_items) - i)) led_matrix.show() f = os.path.join(os.path.dirname(os.path.abspath(__file__)), item[1]) if not os.path.isfile(f): raise IOError("File '" + f + "' could not be found.") items.append({ "title": item[0], "file": f, "text": led_matrix.LEDText(item[0], font_name="large") }) self.items = items self.scrolling_text_pos = 0 self.scrolling_text_clock = Menu.HOLD_CLOCK_TIME # clock used to slow down scrolling text self.scrolling_text_cycle = 5 # number of cycles between scrolling tick
if ret == False: state = State.SCORE time.sleep(.1) elif state == State.IDLE: x = led_matrix.width() while x > -title.width: # break if state has changed, (don't wait for scroll to finish) if state != State.IDLE: break led_matrix.erase() led_matrix.sprite(title, (x, led_matrix.height() / 2 - (title.height / 2))) led_matrix.show() x -= 1 time.sleep(.05) elif state == State.SCORE: led_matrix.erase() led_matrix.text(str(len(field.strikers))) # led_matrix.text(str(len(field.horizontal_strikers) + len(field.vertical_strikers))) led_matrix.show() elif state == State.EXIT: GPIO.cleanup() led_matrix.cleanup() sys.exit(0) else: raise ValueError("Invalid State")
print("P70") sys.stdout.flush() GPIO.setmode(GPIO.BCM) GPIO.setup(START, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(SELECT, GPIO.IN, pull_up_down=GPIO.PUD_UP) # notify of progress print("P100") sys.stdout.flush() # notify menu we are ready for the led matrix print("READY") sys.stdout.flush() while True: if GPIO.input(START) == 0 or GPIO.input(SELECT) == 0: button.cleanup() led_matrix.cleanup() sys.exit(0) hour = time.strftime("%I", time.localtime()) hour = led_matrix.LEDText(hour) minute = time.strftime("%M", time.localtime()) minute = led_matrix.LEDText(minute) led_matrix.erase() led_matrix.text(hour) led_matrix.text(minute, (hour.width + 2, 0)) led_matrix.show()
if state.current() == WALL_SCENE: state.next_if_after(10) elif state.current() == WALL_2_ENEMY_SCENE: state.next_if_after(3) elif state.current() == ENEMY_SCENE: if len(enemies) == 0: # if all enemies killed state.next() elif state.current() == BIG_BOSS: state.next() elif state.current() == GAME_OVER: # Scroll "GAME OVER" message text = led_matrix.LEDText("GAME OVER!!!") pos_x, pos_y = (led_matrix.width(), 0) while -pos_x < text.width: if exit: break # break if user pressed the start button time.sleep(.1) led_matrix.erase() led_matrix.text(text, (pos_x, pos_y)) led_matrix.show() pos_x -= 1 state.next() t = next_tick - time.time() if t > 0: time.sleep(t) next_tick += POLL_PERIOD
# global button_pressed if blocks[-1].moving: # change direction if hit edge of screen if curr_direction == Direction.RIGHT: if blocks[-1].origin[0] + blocks[-1].width == RIGHT_EDGE: curr_direction = Direction.LEFT elif blocks[-1].origin[0] == LEFT_EDGE+1: curr_direction = Direction.RIGHT # move top block in curr_direction at curr_speed blocks[-1].move(curr_direction) elif curr_state == State.WIN: led_matrix.erase() led_matrix.text("WIN!") led_matrix.show() elif curr_state == State.LOSE: # blink failing block blocks[-1].color = 0 led_matrix.erase() draw_blocks() # draw edge lines if not whole screen if LEFT_EDGE != 0: led_matrix.line((LEFT_EDGE, 0), (LEFT_EDGE, HEIGHT-1)) if RIGHT_EDGE != WIDTH: led_matrix.line((RIGHT_EDGE, 0), (RIGHT_EDGE, HEIGHT-1)) led_matrix.show() time.sleep(.2) led_matrix.erase()
field.new_apple(snake) field.draw_apple() led_matrix.show() curr_state = State.PLAYING elif curr_state == State.WIN: # display horizontal scrolling win screen title = led_matrix.LEDText("WIN!!") x_pos = led_matrix.width() - 1 while x_pos > - title.width: if curr_state != State.WIN: break led_matrix.erase() led_matrix.sprite(title, (x_pos, 1)) led_matrix.show() time.sleep(.1) x_pos -= 1 elif curr_state == State.LOSE: led_matrix.erase() led_matrix.text(str(score)) led_matrix.show() elif curr_state == State.EXIT: led_matrix.cleanup() GPIO.cleanup() sys.exit(0)
import time 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. # Displaying multiple pieces of text in succession =============================================== # create a while loop that loops infinitly while True: # clear the display led_matrix.erase() # draw the first part of text led_matrix.text("Hello") # display the text led_matrix.show() # delay for a second so we can see the text time.sleep(1) # clear the display again so we can display the next part led_matrix.erase() # draw the next part of the text led_matrix.text("World") # display the text led_matrix.show()
from rstem import led_matrix import time 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. # Displaying text on the led matrix. =============================================== # Draw the text "hello" on the LED matrix # NOTE: this doesn't actually show the text on the display until we call led_matrix.show() led_matrix.text("hello") # To be able to see the text we need to tell the Raspberry Pi to show the drawn text on the led matrix. led_matrix.show() # Yay!! We can see the text on the led matrix! # Try changing "Hello World" to something else and see what you get. :) (Don't forget the " " )
if state.current() == WALL_SCENE: state.next_if_after(10) elif state.current() == WALL_2_ENEMY_SCENE: state.next_if_after(3) elif state.current() == ENEMY_SCENE: if len(enemies) == 0: # if all enemies killed state.next() elif state.current() == BIG_BOSS: state.next() elif state.current() == GAME_OVER: # Scroll "GAME OVER" message text = led_matrix.LEDText("GAME OVER!!!") pos_x, pos_y = (led_matrix.width(),0) while -pos_x < text.width: if exit: break # break if user pressed the start button time.sleep(.1) led_matrix.erase() led_matrix.text(text, (pos_x, pos_y)) led_matrix.show() pos_x -= 1 state.next() t = next_tick - time.time() if t > 0: time.sleep(t) next_tick += POLL_PERIOD
led_matrix.sprite( title, (int(led_matrix.width() / 2) - int(title.width / 2), y_pos)) led_matrix.show() y_pos += 1 time.sleep(.1) elif curr_state == State.RESET: score = 0 stack = None if led_matrix.width() < 16: stack = Stack() else: stack = Stack( 8) # if screen too width only use left half for stack sidebar = None sidebar = Sidebar(8) curr_piece = Piece(random.choice(SHAPES)) next_piece = Piece(random.choice(SHAPES)) curr_state = State.MOVINGDOWN elif curr_state == State.DONE: led_matrix.erase() led_matrix.text(str(score)) led_matrix.show() elif curr_state == State.EXIT: GPIO.cleanup() led_matrix.cleanup() sys.exit(0)
elif state == State.IDLE: x = led_matrix.width() while x > -title.width: # break if state has changed, (don't wait for scroll to finish) if state != State.IDLE: break led_matrix.erase() led_matrix.sprite(title, (x, led_matrix.height()/2 - (title.height/2))) led_matrix.show() x -= 1 time.sleep(.05) elif state == State.SCORE: led_matrix.erase() led_matrix.text(str(len(field.strikers))) # led_matrix.text(str(len(field.horizontal_strikers) + len(field.vertical_strikers))) led_matrix.show() elif state == State.EXIT: GPIO.cleanup() led_matrix.cleanup() sys.exit(0) else: raise ValueError("Invalid State")
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. # Displaying multiple pieces of text in succession =============================================== # create a while loop that loops infinitly while True: # clear the display led_matrix.erase() # draw the first part of text led_matrix.text("Hello") # display the text led_matrix.show() # delay for a second so we can see the text time.sleep(1) # clear the display again so we can display the next part led_matrix.erase() # draw the next part of the text led_matrix.text("World") # display the text led_matrix.show()
from rstem import led_matrix import time 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. # Displaying text on the led matrix. =============================================== # Draw the text "hello" on the LED matrix # NOTE: this doesn't actually show the text on the display until we call led_matrix.show() led_matrix.text("hello") # To be able to see the text we need to tell the Raspberry Pi to show the drawn text on the led matrix. led_matrix.show() # Yay!! We can see the text on the led matrix! # Try changing "Hello World" to something else and see what you get. :) (Don't forget the " " )
# global button_pressed if blocks[-1].moving: # change direction if hit edge of screen if curr_direction == Direction.RIGHT: if blocks[-1].origin[0] + blocks[-1].width == RIGHT_EDGE: curr_direction = Direction.LEFT elif blocks[-1].origin[0] == LEFT_EDGE + 1: curr_direction = Direction.RIGHT # move top block in curr_direction at curr_speed blocks[-1].move(curr_direction) elif curr_state == State.WIN: led_matrix.erase() led_matrix.text("WIN!") led_matrix.show() elif curr_state == State.LOSE: # blink failing block blocks[-1].color = 0 led_matrix.erase() draw_blocks() # draw edge lines if not whole screen if LEFT_EDGE != 0: led_matrix.line((LEFT_EDGE, 0), (LEFT_EDGE, HEIGHT - 1)) if RIGHT_EDGE != WIDTH: led_matrix.line((RIGHT_EDGE, 0), (RIGHT_EDGE, HEIGHT - 1)) led_matrix.show() time.sleep(.2) led_matrix.erase()