コード例 #1
0
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)

    print(angle)
    print(x)
    print(y)

    # IF orientation matches the arrow...
    if x == -1 and angle == 180:
        # ADD a point and turn the arrow green
        sense.set_pixels(arrow_green)
コード例 #2
0
# import the Sense Hat emulator module
from sense_emu import SenseHat
import time


# create a SenseHat object
sense = SenseHat()

# print out the temperature, humidity, atmospheric pressure,
# and raw accelerometer from the SenseHat emulated sensors
print('The temperature is ',sense.get_temperature(),'degrees Celsius')
print('The humidity is ',sense.get_humidity(),'%')
print('The atmospheric pressure is ',sense.get_pressure(),'millibars')
print('The raw accelerometer data is ',sense.get_accelerometer_raw())


sense.show_message('Marques',scroll_speed=0.1, text_colour=[255,69,0])


w = (200, 200, 200) # the color white
p = (102, 0, 153)   # the color purple

letter = [
    w, w, w, w, w, w, w, w,
    w, p, p, p, p, p, w, w,
    w, p, w, w, w, w, p, w,
    w, p, w, w, w, w, p, w,
    w, p, p, p, p, p, w, w,
    w, p, w, w, p, w, w, w,
    w, p, w, w, w, p, w, w,
    w, p, w, w, w, w, p, w
コード例 #3
0
            printEvent(event)
            if event.direction == "right":
                newMode += 1
                if(newMode > 2):
                    newMode = 1
            elif event.direction == "middle":
                if(mode != switchMode):
                    newMode = mode
                    mode = switchMode
                else:
                    mode = newMode


    rotate = rotate0
    hat.set_imu_config(compass_enabled=False,gyro_enabled=False,accel_enabled=True)
    a = hat.get_accelerometer_raw()
    x = a['x']
    y = a['y']
    z = a['z']
    if abs(x) < 0.1:
        x = 0
    if abs(y) < 0.1:
        y = 0
    if abs(z) < 0.1:
        z = 0
    if x < -0.9:
        x = -1
    if y < -0.9:
        y = -1
    if z < -0.9:
        z = -1
コード例 #4
0
ファイル: acceleration.py プロジェクト: talyo94/pi_lecture
from sense_emu import SenseHat

hat = SenseHat()
while True:
    acceleration = hat.get_accelerometer_raw()
    print(acceleration)