コード例 #1
0
angle = 0
play = True

sense.show_message("Keep the arrow pointing up",
                   scroll_speed=0.05,
                   text_colour=[100, 100, 100])

# WHILE play == True
while play:

    # CHOOSE a new random angle
    last_angle = angle
    while angle == last_angle:
        angle = choice([0, 90, 180, 270])

    sense.set_rotation(angle)

    # DISPLAY the white arrow
    sense.set_pixels(arrow)

    # SLEEP for current pause length
    sleep(pause)

    acceleration = sense.get_accelerometer_raw()
    x = acceleration['x']
    y = acceleration['y']
    z = acceleration['z']

    x = round(x, 0)
    y = round(y, 0)
コード例 #2
0
import time
from PIL import Image
import os

# Open image file
image_file = os.path.join(os.sep, "/home", "pi", "GlosLibCodeClub", "Coders",
                          "Martha", "example1.png")
img = Image.open(image_file)

# generate rbg values for image pixels
rbg_img = img.convert('RGB')
image_pixels = list(rbg_img.getdata())

# Get the 64 Pixels you need
pixel_width = 1
image_width = pixel_width * 8
sense_pixels = []
start_pixel = 0
while start_pixel < (image_width * 64):
    sense_pixels.extend(image_pixels[start_pixel:(start_pixel +
                                                  image_width):pixel_width])
    start_pixel += (image_width * pixel_width)

# Display the image
sense = SenseHat()
sense.set_rotation(r=180)
sense.set_pixels(sense_pixels)
time.sleep(30)

sense.clear()
コード例 #3
0

def random_colour():
    return (randint(0, 255), randint(0, 255), randint(0, 255))


# Arrow
# Define some colours
g = green
b = black
w = white

# Set up where each colour will display
pixels = [
    b, b, b, w, w, b, b, b, b, b, b, w, w, b, b, b, b, b, b, w, w, b, b, b, b,
    b, b, w, w, b, b, b, b, b, b, w, w, b, b, b, b, w, w, w, w, w, w, b, b, b,
    w, w, w, w, b, b, b, b, b, w, w, b, b, b
]

# Display these colours on the LED matrix
sense.set_pixels(pixels)

rotations = [0, 90, 180, 270]
r = 1
while True:
    sense.set_rotation(rotations[r])
    sleep(1)
    r = r + 1
    if r >= len(rotations):
        r = 0
コード例 #4
0
from time import sleep
from sense_emu import SenseHat

sense = SenseHat()
sense.clear()

while True:
    acceleration = sense.get_accelerometer_raw()

    x = acceleration['x']
    y = acceleration['y']
    z = acceleration['z']

    if abs(x) > 1 or abs(y) > 1 or abs(z) > 1:
        sense.show_letter("!", (255, 0, 0))
    else:
        sense.show_letter("M", (255, 255, 255))

        print("x: {:.1f} y: {:.1f} z: {:.1f}".format(x, y, z))
        x = round(acceleration['x'], 0)
        y = round(acceleration['y'], 0)
        z = round(acceleration['z'], 0)
        if x == -1:
            sense.set_rotation(180)
        elif y == 1:
            sense.set_rotation(90)
        elif y == -1:
            sense.set_rotation(270)
        else:
            sense.set_rotation(0)
コード例 #5
0
ファイル: Harness.py プロジェクト: sbrady316/PiPy-Random
#
print(sys.argv)
if len(sys.argv) > 1:
    pattern = sys.argv[1]
else:
    pattern = 'Move'

if len(sys.argv) > 2:
    senseOption = sys.argv[2]
else:
    senseOption = 'UnSet'
# senseOption = os.environ.get("SenseHat", "Unset")
#print(f'SenseOption = {senseOption}')
if senseOption == "EMU":
    print("Using emulator per SenseHat setting...")
    from sense_emu import SenseHat
else:
    print("Using the real Sense Hat...")
    from sense_hat import SenseHat
# print(f'{sys.argv[0]} {pattern} {senseOption}')

sense = SenseHat()
sense.set_rotation(180)  # Allows power supply to be away from viewer

if pattern == 'All':
    for opName, opValue in Movement.Operations.items():
        DoPattern(sense, opName, opValue)
else:
    opValue = Movement.Operations.get(pattern, Movement.MoveQuick)
    DoPattern(sense, pattern, opValue)
コード例 #6
0
ファイル: iss-ready.py プロジェクト: janusson/missionzero
from time import sleep
from sense_emu import SenseHat
sense = SenseHat()
#rotate scren for astro-pi use
sense.set_rotation(270)

red = (255,0,0)
green = (0,255,0)
sense.show_message("Hello ISS from Egham Raspberry Jam", text_colour=red, back_colour=green)
w = (255, 255, 255)
b = (0, 0, 0)
y = (255, 255, 0)
g = (0, 255, 0)
picture = [
            b, b, w, w, w, w, b, b,
            b, w, b, b, b, b, w, b,
            b, w, b, w, w, b, w, b,
            b, w, b, b, b, b, w, b,
            b, b, w, w, w, w, b, b,
            b, b, w, w, w, w, b, b,
            b, w, w, w, w, w, w, b,
            b, w, w, w, w, w, w, b
        ]
hot = [
        b, b, b, b, b, y, y, b,
        b, b, b, b, y, y, y, y,
        b, b, b, b, b, y, y, b,
        b, b, b, b, b, b, b, b,
        b, b, b, b, b, b, b, b,
        b, b, b, b, b, b, b, b,
        g, g, g, g, g, g, g, g,