Simple test

Ensure your device works with this simple test.

examples/monsterm4sk_simpletest.py
 1# SPDX-FileCopyrightText: 2020 Foamyguy, written for Adafruit Industries
 2#
 3# SPDX-License-Identifier: Unlicense
 4
 5"""
 6CircuitPython example for Monster M4sk.
 7
 8Draws a basic eye dot on each screen. Looks at nose
 9when booped. Prints acceleration and light sensor
10data when booped as well.
11"""
12import time
13import board
14import displayio
15from adafruit_display_shapes.circle import Circle
16import adafruit_monsterm4sk
17
18
19# Account for slight screen difference if you want
20LEFT_Y_OFFSET = 0  # 12 # my left screen is a tad higher
21
22SCREEN_SIZE = 240
23
24i2c_bus = board.I2C()  # uses board.SCL and board.SDA
25# i2c_bus = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
26
27mask = adafruit_monsterm4sk.MonsterM4sk(i2c=i2c_bus)
28
29left_group = displayio.Group()
30mask.left_display.show(left_group)
31
32right_group = displayio.Group()
33mask.right_display.show(right_group)
34
35right_circle = Circle(SCREEN_SIZE // 2, SCREEN_SIZE // 2, 40, fill=0x0000FF)
36right_group.append(right_circle)
37
38left_circle = Circle(SCREEN_SIZE // 2, SCREEN_SIZE // 2, 40, fill=0x00AA66)
39left_group.append(left_circle)
40
41while True:
42    # print(mask.boop)
43    if mask.boop:
44        left_circle.x = 0
45        right_circle.x = SCREEN_SIZE - 40 - 40 - 2
46
47        right_circle.y = SCREEN_SIZE // 4 - 40
48        left_circle.y = SCREEN_SIZE // 4 - 40 + LEFT_Y_OFFSET
49        print(mask.acceleration)
50        print(mask.light)
51        time.sleep(0.5)
52    else:
53        left_circle.x = SCREEN_SIZE // 2 - 40
54        right_circle.x = SCREEN_SIZE // 2 - 40
55
56        right_circle.y = SCREEN_SIZE // 2 - 40
57        left_circle.y = SCREEN_SIZE // 2 - 40 + LEFT_Y_OFFSET

Rainbow Stars

Groovy color changing stars eyes.

examples/monsterm4sk_rainbow_stars.py
 1# SPDX-FileCopyrightText: 2020 Foamyguy, written for Adafruit Industries
 2#
 3# SPDX-License-Identifier: Unlicense
 4
 5"""
 6CircuitPython example for Monster M4sk.
 7
 8Draws star images on each screen. When buttons are pressed
 9set the stars to a different color. When the nose is booped
10make the eyes change through the rainbow.
11"""
12
13import time
14import board
15import displayio
16import adafruit_imageload
17import adafruit_monsterm4sk
18
19
20SCREEN_SIZE = 240
21IMAGE_SIZE = 64 * 3
22
23i2c_bus = board.I2C()  # uses board.SCL and board.SDA
24# i2c_bus = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
25
26mask = adafruit_monsterm4sk.MonsterM4sk(i2c=i2c_bus)
27
28left_group = displayio.Group(scale=3)
29mask.left_display.show(left_group)
30
31right_group = displayio.Group(scale=3)
32mask.right_display.show(right_group)
33
34left_group.x = (SCREEN_SIZE - IMAGE_SIZE) // 2
35left_group.y = (SCREEN_SIZE - IMAGE_SIZE) // 2
36
37right_group.x = (SCREEN_SIZE - IMAGE_SIZE) // 2
38right_group.y = (SCREEN_SIZE - IMAGE_SIZE) // 2
39
40#  load in party parrot bitmap
41star_bitmap, star_palette = adafruit_imageload.load(
42    "/rainbow_star.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette
43)
44
45right_star_grid = displayio.TileGrid(
46    star_bitmap,
47    pixel_shader=star_palette,
48    width=1,
49    height=1,
50    tile_height=64,
51    tile_width=64,
52    default_tile=0,
53    x=0,
54    y=0,
55)
56
57left_star_grid = displayio.TileGrid(
58    star_bitmap,
59    pixel_shader=star_palette,
60    width=1,
61    height=1,
62    tile_height=64,
63    tile_width=64,
64    default_tile=0,
65    x=0,
66    y=0,
67)
68
69right_group.append(right_star_grid)
70left_group.append(left_star_grid)
71while True:
72    if mask.boop:
73        for i in range(6 * 3):
74            right_star_grid[0] = i % 6
75            left_star_grid[0] = i % 6
76            time.sleep(0.02)
77        time.sleep(0.5)
78
79    if mask.buttons["S9"]:
80        right_star_grid[0] = 2
81        left_star_grid[0] = 2
82
83    if mask.buttons["S10"]:
84        right_star_grid[0] = 4
85        left_star_grid[0] = 4
86
87    if mask.buttons["S11"]:
88        right_star_grid[0] = 3
89        left_star_grid[0] = 3

Pumpkin Shifting Eyes

Triangle Jack-O-Lantern eyes that shift back and forth.

examples/monsterm4sk_pumpkin_shifting_eyes.py
  1# SPDX-FileCopyrightText: 2020 Foamyguy, written for Adafruit Industries
  2#
  3# SPDX-License-Identifier: Unlicense
  4
  5"""
  6CircuitPython example for Monster M4sk.
  7
  8Draws a yellow triangle on each screen as Jack-O-Lantern eyes.
  9The eyes shift back and forth from left to right.
 10"""
 11
 12import time
 13import board
 14import displayio
 15import adafruit_imageload
 16import adafruit_monsterm4sk
 17
 18SCREEN_SIZE = 240
 19IMAGE_SIZE = 173
 20
 21# Create a bitmap for the background 10x10 pixels
 22bg_color_pixel = displayio.Bitmap(10, 10, 1)
 23
 24# Create a two color palette
 25bg_palette = displayio.Palette(2)
 26bg_palette[0] = 0xFF7700  # orange
 27
 28bg_color_pixel.fill(0)  # fill orange
 29
 30# Create a TileGrid for the orange background
 31bg_left_tile_grid = displayio.TileGrid(bg_color_pixel, pixel_shader=bg_palette)
 32bg_right_tile_grid = displayio.TileGrid(bg_color_pixel, pixel_shader=bg_palette)
 33
 34# Create background groups scaled 24x to match screen size
 35bg_left_group = displayio.Group(scale=24)
 36bg_right_group = displayio.Group(scale=24)
 37
 38# add the background tilegrids to the scaled groups
 39bg_left_group.append(bg_left_tile_grid)
 40bg_right_group.append(bg_right_tile_grid)
 41
 42# load the eye image
 43eye_image, eye_palette = adafruit_imageload.load(
 44    "/small_triangle_eye.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette
 45)
 46
 47# Create a TileGrid to hold the bitmap for each eye
 48right_pumkin_eye_tilegrid = displayio.TileGrid(eye_image, pixel_shader=eye_palette)
 49left_pumkin_eye_tilegrid = displayio.TileGrid(eye_image, pixel_shader=eye_palette)
 50
 51# initialize the monster m4sk hardware
 52i2c_bus = board.I2C()  # uses board.SCL and board.SDA
 53# i2c_bus = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
 54mask = adafruit_monsterm4sk.MonsterM4sk(i2c=i2c_bus)
 55
 56# left eye group setup
 57left_group = displayio.Group()
 58mask.left_display.show(left_group)
 59
 60# right eye group setup
 61right_group = displayio.Group()
 62mask.right_display.show(right_group)
 63
 64# Add orange backgrounds to both groups
 65right_group.append(bg_right_group)
 66left_group.append(bg_left_group)
 67
 68# add triangle eyes to both groups
 69right_group.append(right_pumkin_eye_tilegrid)
 70left_group.append(left_pumkin_eye_tilegrid)
 71
 72# centered vertically
 73right_pumkin_eye_tilegrid.y = (SCREEN_SIZE - IMAGE_SIZE) // 2
 74left_pumkin_eye_tilegrid.y = (SCREEN_SIZE - IMAGE_SIZE) // 2
 75
 76while True:
 77    # move the eyes to the right
 78    for i in range(0, 240 - 173, 5):
 79        right_pumkin_eye_tilegrid.x = i
 80        left_pumkin_eye_tilegrid.x = i
 81        time.sleep(0.01)
 82
 83    time.sleep(2)  # wait 2 seconds
 84
 85    # move the eyes to the left
 86    for i in range(0, 240 - 173, 5):
 87        right_pumkin_eye_tilegrid.x -= 5
 88        left_pumkin_eye_tilegrid.x -= 5
 89        time.sleep(0.01)
 90
 91    time.sleep(2)  # wait 2 seconds
 92
 93    if mask.boop:
 94        pass
 95
 96    if mask.buttons["S9"]:
 97        pass
 98
 99    if mask.buttons["S10"]:
100        pass
101
102    if mask.buttons["S11"]:
103        pass