예제 #1
0
#!/usr/bin/env python
import numpy as np
import cv2
from rstem import led_matrix
ANGLE_FACTOR = 1
GRID_SIZE = 6
IMAGE_SIZE = ANGLE_FACTOR*8*GRID_SIZE
cap = cv2.VideoCapture(0)
cap.set(3, IMAGE_SIZE) #width
cap.set(4, IMAGE_SIZE) #height
cap.set(11, 1)
led_matrix.init_grid(GRID_SIZE, GRID_SIZE)
offset = int(round( (IMAGE_SIZE-(8*GRID_SIZE))/2 ))
try:
	while True:
		ret, img = cap.read()
		img = cv2.flip(img, 0)
		new_img = img[offset:offset+8*GRID_SIZE,offset:offset+8*GRID_SIZE]
		grey = cv2.cvtColor(new_img, cv2.COLOR_BGR2GRAY)
		canny = cv2.Canny(grey, 100, 200)
		led_matrix.frame(canny)
		led_matrix.show()
except KeyboardInterrupt:	
	pass
finally:
	led_matrix.cleanup()
	cap.release()

예제 #2
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. Create a speech object of "Hello World"
my_speech = speaker.Speech("Hello World")

# 3. Play my_speech
my_speech.play()

# 4. Create a while loop that keeps looping until the Raspberry Pi has stopped talking.
while my_speech.is_playing():

    # 5. Clear the led matrix
    led_matrix.erase()
    
    # 6. Draw the face with its mouth open
    led_matrix.sprite(mouth_open)
    
    # 7. Show the new face on the display and add a delay
    led_matrix.show()
    time.sleep(.1)
    
    # 8. Clear the led matrix of the previous face
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#This is the second project in the "Space invaders" series.
#This project adds missles to the game when the player
#presses the button.

#Imports, need sys for exit function
from rstem import led_matrix
from rstem import accel
import RPi.GPIO as GPIO
import time

#Initialize matrix, accelerometer, and GPIO, the matrix layout and accelerometer channel may changes from user to user
led_matrix.init_grid(2)
accel.init(1)
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN, pull_up_down=GPIO.PUD_UP)

#Game entity data
player_pos = [7, 0]
missles = []

#Game timing data, missles get updated and therefore move roughly sixty times faster than enemies initialy
game_tick = 0
game_tick_max = 64
enemy_tick = 60
start_time = time.time()

예제 #4
0
#In this project the user adds the Ball class, which handles
#most of the game physics, and adds the win and lose functions.

#Imports
from rstem import led_matrix
from rstem import accel
import sys
import time

#Initialize hardware
led_matrix.init_grid(2, 2)
accel.init(1)

#Initialize game data
bricks = []
score = 0
start_time = time.time()
ball_tick = 0
MAX_BALL_TICK = 8
#Useful clamp function
def clamp(value, minimum, maximum):
	return min(maximum, max(value, minimum))

#Display losing score
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()
예제 #5
0
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.


# Scrolling the led matrix. ===============================================

# Create a variable that holds information about the sprite
my_text_sprite = led_matrix.LEDText("Hello World!")

# Make a while loop that keeps looping forever
while True:  # by making the conditional True, the while loop will never break because True is always True!
   
    # Get the width of the text in pixels.
    text_width = my_text_sprite.width   # this is the number of LEDs wide our my_text_sprite is.

    # Set the original x value to be the width of the led matrix display.
    x = led_matrix.width()   # this is the number of LEDs wide the display is. 
    
    # Make another while loop that keeps moving the text to the left.
    #   - When x is less then -text_width, our text will not be on the display anymore.
    #   - When this happens we want to stop this while loop and run through the outside while loop.
    while x > -text_width:   # when x is less then -text_width, our text will not be on the display anymore
        
        # Erase the previous drawn text
        led_matrix.erase()
        
        # Draw the text at this current x position
        led_matrix.sprite(text, (x, 0))
예제 #6
0
#!/usr/bin/env python
import numpy as np
import cv2
from rstem import led_matrix
ANGLE_FACTOR = 1
GRID_SIZE = 6
IMAGE_SIZE = ANGLE_FACTOR * 8 * GRID_SIZE
cap = cv2.VideoCapture(0)
cap.set(3, IMAGE_SIZE)  #width
cap.set(4, IMAGE_SIZE)  #height
cap.set(11, 1)
led_matrix.init_grid(GRID_SIZE, GRID_SIZE)
offset = int(round((IMAGE_SIZE - (8 * GRID_SIZE)) / 2))
try:
    while True:
        ret, img = cap.read()
        img = cv2.flip(img, 0)
        new_img = img[offset:offset + 8 * GRID_SIZE,
                      offset:offset + 8 * GRID_SIZE]
        grey = cv2.cvtColor(new_img, cv2.COLOR_BGR2GRAY)
        canny = cv2.Canny(grey, 100, 200)
        led_matrix.frame(canny)
        led_matrix.show()
except KeyboardInterrupt:
    pass
finally:
    led_matrix.cleanup()
    cap.release()