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()
25
26mask = adafruit_monsterm4sk.MonsterM4sk(i2c=i2c_bus)
27
28left_group = displayio.Group()
29mask.left_display.show(left_group)
30
31right_group = displayio.Group()
32mask.right_display.show(right_group)
33
34right_circle = Circle(SCREEN_SIZE // 2, SCREEN_SIZE // 2, 40, fill=0x0000FF)
35right_group.append(right_circle)
36
37left_circle = Circle(SCREEN_SIZE // 2, SCREEN_SIZE // 2, 40, fill=0x00AA66)
38left_group.append(left_circle)
39
40while True:
41    # print(mask.boop)
42    if mask.boop:
43        left_circle.x = 0
44        right_circle.x = SCREEN_SIZE - 40 - 40 - 2
45
46        right_circle.y = SCREEN_SIZE // 4 - 40
47        left_circle.y = SCREEN_SIZE // 4 - 40 + LEFT_Y_OFFSET
48        print(mask.acceleration)
49        print(mask.light)
50        time.sleep(0.5)
51    else:
52        left_circle.x = SCREEN_SIZE // 2 - 40
53        right_circle.x = SCREEN_SIZE // 2 - 40
54
55        right_circle.y = SCREEN_SIZE // 2 - 40
56        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()
24
25mask = adafruit_monsterm4sk.MonsterM4sk(i2c=i2c_bus)
26
27left_group = displayio.Group(scale=3)
28mask.left_display.show(left_group)
29
30right_group = displayio.Group(scale=3)
31mask.right_display.show(right_group)
32
33left_group.x = (SCREEN_SIZE - IMAGE_SIZE) // 2
34left_group.y = (SCREEN_SIZE - IMAGE_SIZE) // 2
35
36right_group.x = (SCREEN_SIZE - IMAGE_SIZE) // 2
37right_group.y = (SCREEN_SIZE - IMAGE_SIZE) // 2
38
39#  load in party parrot bitmap
40star_bitmap, star_palette = adafruit_imageload.load(
41    "/rainbow_star.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette
42)
43
44right_star_grid = displayio.TileGrid(
45    star_bitmap,
46    pixel_shader=star_palette,
47    width=1,
48    height=1,
49    tile_height=64,
50    tile_width=64,
51    default_tile=0,
52    x=0,
53    y=0,
54)
55
56left_star_grid = displayio.TileGrid(
57    star_bitmap,
58    pixel_shader=star_palette,
59    width=1,
60    height=1,
61    tile_height=64,
62    tile_width=64,
63    default_tile=0,
64    x=0,
65    y=0,
66)
67
68right_group.append(right_star_grid)
69left_group.append(left_star_grid)
70while True:
71    if mask.boop:
72        for i in range(6 * 3):
73            right_star_grid[0] = i % 6
74            left_star_grid[0] = i % 6
75            time.sleep(0.02)
76        time.sleep(0.5)
77
78    if mask.buttons["S9"]:
79        right_star_grid[0] = 2
80        left_star_grid[0] = 2
81
82    if mask.buttons["S10"]:
83        right_star_grid[0] = 4
84        left_star_grid[0] = 4
85
86    if mask.buttons["S11"]:
87        right_star_grid[0] = 3
88        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()
 53mask = adafruit_monsterm4sk.MonsterM4sk(i2c=i2c_bus)
 54
 55# left eye group setup
 56left_group = displayio.Group()
 57mask.left_display.show(left_group)
 58
 59# right eye group setup
 60right_group = displayio.Group()
 61mask.right_display.show(right_group)
 62
 63# Add orange backgrounds to both groups
 64right_group.append(bg_right_group)
 65left_group.append(bg_left_group)
 66
 67# add triangle eyes to both groups
 68right_group.append(right_pumkin_eye_tilegrid)
 69left_group.append(left_pumkin_eye_tilegrid)
 70
 71# centered vertically
 72right_pumkin_eye_tilegrid.y = (SCREEN_SIZE - IMAGE_SIZE) // 2
 73left_pumkin_eye_tilegrid.y = (SCREEN_SIZE - IMAGE_SIZE) // 2
 74
 75while True:
 76    # move the eyes to the right
 77    for i in range(0, 240 - 173, 5):
 78        right_pumkin_eye_tilegrid.x = i
 79        left_pumkin_eye_tilegrid.x = i
 80        time.sleep(0.01)
 81
 82    time.sleep(2)  # wait 2 seconds
 83
 84    # move the eyes to the left
 85    for i in range(0, 240 - 173, 5):
 86        right_pumkin_eye_tilegrid.x -= 5
 87        left_pumkin_eye_tilegrid.x -= 5
 88        time.sleep(0.01)
 89
 90    time.sleep(2)  # wait 2 seconds
 91
 92    if mask.boop:
 93        pass
 94
 95    if mask.buttons["S9"]:
 96        pass
 97
 98    if mask.buttons["S10"]:
 99        pass
100
101    if mask.buttons["S11"]:
102        pass