|
11 | 11 | import busio |
12 | 12 | import adafruit_lis3dh |
13 | 13 |
|
14 | | -backlight = pulseio.PWMOut(board.TFT_BACKLIGHT) |
15 | 14 | splash = displayio.Group() |
16 | 15 | board.DISPLAY.show(splash) |
17 | 16 |
|
18 | | -max_brightness = 2 ** 15 |
19 | 17 | SENSITIVITY = 5 # reading in Z direction to trigger, adjustable |
20 | 18 |
|
21 | 19 | images = list(filter(lambda x: x.endswith("bmp"), os.listdir("/"))) |
22 | 20 |
|
23 | 21 | i = random.randint(0, (len(images)-1)) # initial image is randomly selected |
24 | 22 |
|
25 | 23 | # Set up accelerometer on I2C bus, 4G range: |
26 | | -I2C = busio.I2C(board.SCL, board.SDA) |
27 | | - |
28 | | -ACCEL = adafruit_lis3dh.LIS3DH_I2C(I2C, address=0x18) |
| 24 | +ACCEL = adafruit_lis3dh.LIS3DH_I2C(board.I2C(), address=0x18) |
29 | 25 |
|
30 | 26 | ACCEL.range = adafruit_lis3dh.RANGE_4_G |
31 | 27 |
|
|
39 | 35 | print("Image unsupported {}".format(images[i])) |
40 | 36 | del images[i] |
41 | 37 | continue |
42 | | - face = displayio.Sprite(odb, pixel_shader=displayio.ColorConverter(), |
43 | | - position=(0, 0)) |
| 38 | + face = displayio.TileGrid(odb, pixel_shader=displayio.ColorConverter()) |
| 39 | + |
44 | 40 | splash.append(face) |
45 | 41 | # Wait for the image to load. |
46 | 42 | board.DISPLAY.wait_for_frame() |
47 | 43 |
|
48 | 44 | # Fade up the backlight |
49 | | - for b in range(100): |
50 | | - backlight.duty_cycle = b * max_brightness // 100 |
| 45 | + for b in range(101): |
| 46 | + board.DISPLAY.brightness = b / 100 |
51 | 47 | time.sleep(0.01) # default (0.01) |
52 | 48 |
|
53 | | - # Wait forever |
| 49 | + # Wait until the board gets shaken |
54 | 50 | while not shaken: |
55 | 51 | try: |
56 | 52 | ACCEL_Z = ACCEL.acceleration[2] # Read Z axis acceleration |
57 | | - except IOError: |
| 53 | + except OSError: |
58 | 54 | pass |
59 | 55 | # print(ACCEL_Z) # uncomment to see the accelerometer z reading |
60 | 56 | if ACCEL_Z > SENSITIVITY: |
61 | 57 | shaken = True |
62 | 58 |
|
63 | 59 | # Fade down the backlight |
64 | | - for b in range(50, -1, -1): |
65 | | - backlight.duty_cycle = b * max_brightness // 100 |
| 60 | + for b in range(100, 0, -1): |
| 61 | + board.DISPLAY.brightness = b |
66 | 62 | time.sleep(0.005) # default (0.005) |
67 | 63 |
|
68 | 64 | splash.pop() |
|
0 commit comments