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"""
12
13import time
14
15import board
16import displayio
17from adafruit_display_shapes.circle import Circle
18
19import adafruit_monsterm4sk
20
21# Account for slight screen difference if you want
22LEFT_Y_OFFSET = 0 # 12 # my left screen is a tad higher
23
24SCREEN_SIZE = 240
25
26i2c_bus = board.I2C() # uses board.SCL and board.SDA
27# i2c_bus = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
28
29mask = adafruit_monsterm4sk.MonsterM4sk(i2c=i2c_bus)
30
31left_group = displayio.Group()
32mask.left_display.root_group = left_group
33
34right_group = displayio.Group()
35mask.right_display.root_group = right_group
36
37right_circle = Circle(SCREEN_SIZE // 2, SCREEN_SIZE // 2, 40, fill=0x0000FF)
38right_group.append(right_circle)
39
40left_circle = Circle(SCREEN_SIZE // 2, SCREEN_SIZE // 2, 40, fill=0x00AA66)
41left_group.append(left_circle)
42
43while True:
44 # print(mask.boop)
45 if mask.boop:
46 left_circle.x = 0
47 right_circle.x = SCREEN_SIZE - 40 - 40 - 2
48
49 right_circle.y = SCREEN_SIZE // 4 - 40
50 left_circle.y = SCREEN_SIZE // 4 - 40 + LEFT_Y_OFFSET
51 print(mask.acceleration)
52 print(mask.light)
53 time.sleep(0.5)
54 else:
55 left_circle.x = SCREEN_SIZE // 2 - 40
56 right_circle.x = SCREEN_SIZE // 2 - 40
57
58 right_circle.y = SCREEN_SIZE // 2 - 40
59 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
14
15import adafruit_imageload
16import board
17import displayio
18
19import adafruit_monsterm4sk
20
21SCREEN_SIZE = 240
22IMAGE_SIZE = 64 * 3
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(scale=3)
30mask.left_display.root_group = left_group
31
32right_group = displayio.Group(scale=3)
33mask.right_display.root_group = right_group
34
35left_group.x = (SCREEN_SIZE - IMAGE_SIZE) // 2
36left_group.y = (SCREEN_SIZE - IMAGE_SIZE) // 2
37
38right_group.x = (SCREEN_SIZE - IMAGE_SIZE) // 2
39right_group.y = (SCREEN_SIZE - IMAGE_SIZE) // 2
40
41# load in party parrot bitmap
42star_bitmap, star_palette = adafruit_imageload.load(
43 "/rainbow_star.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette
44)
45
46right_star_grid = displayio.TileGrid(
47 star_bitmap,
48 pixel_shader=star_palette,
49 width=1,
50 height=1,
51 tile_height=64,
52 tile_width=64,
53 default_tile=0,
54 x=0,
55 y=0,
56)
57
58left_star_grid = displayio.TileGrid(
59 star_bitmap,
60 pixel_shader=star_palette,
61 width=1,
62 height=1,
63 tile_height=64,
64 tile_width=64,
65 default_tile=0,
66 x=0,
67 y=0,
68)
69
70right_group.append(right_star_grid)
71left_group.append(left_star_grid)
72while True:
73 if mask.boop:
74 for i in range(6 * 3):
75 right_star_grid[0] = i % 6
76 left_star_grid[0] = i % 6
77 time.sleep(0.02)
78 time.sleep(0.5)
79
80 if mask.buttons["S9"]:
81 right_star_grid[0] = 2
82 left_star_grid[0] = 2
83
84 if mask.buttons["S10"]:
85 right_star_grid[0] = 4
86 left_star_grid[0] = 4
87
88 if mask.buttons["S11"]:
89 right_star_grid[0] = 3
90 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
13
14import adafruit_imageload
15import board
16import displayio
17
18import adafruit_monsterm4sk
19
20SCREEN_SIZE = 240
21IMAGE_SIZE = 173
22
23# Create a bitmap for the background 10x10 pixels
24bg_color_pixel = displayio.Bitmap(10, 10, 1)
25
26# Create a two color palette
27bg_palette = displayio.Palette(2)
28bg_palette[0] = 0xFF7700 # orange
29
30bg_color_pixel.fill(0) # fill orange
31
32# Create a TileGrid for the orange background
33bg_left_tile_grid = displayio.TileGrid(bg_color_pixel, pixel_shader=bg_palette)
34bg_right_tile_grid = displayio.TileGrid(bg_color_pixel, pixel_shader=bg_palette)
35
36# Create background groups scaled 24x to match screen size
37bg_left_group = displayio.Group(scale=24)
38bg_right_group = displayio.Group(scale=24)
39
40# add the background tilegrids to the scaled groups
41bg_left_group.append(bg_left_tile_grid)
42bg_right_group.append(bg_right_tile_grid)
43
44# load the eye image
45eye_image, eye_palette = adafruit_imageload.load(
46 "/small_triangle_eye.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette
47)
48
49# Create a TileGrid to hold the bitmap for each eye
50right_pumkin_eye_tilegrid = displayio.TileGrid(eye_image, pixel_shader=eye_palette)
51left_pumkin_eye_tilegrid = displayio.TileGrid(eye_image, pixel_shader=eye_palette)
52
53# initialize the monster m4sk hardware
54i2c_bus = board.I2C() # uses board.SCL and board.SDA
55# i2c_bus = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
56mask = adafruit_monsterm4sk.MonsterM4sk(i2c=i2c_bus)
57
58# left eye group setup
59left_group = displayio.Group()
60mask.left_display.root_group = left_group
61
62# right eye group setup
63right_group = displayio.Group()
64mask.right_display.root_group = right_group
65
66# Add orange backgrounds to both groups
67right_group.append(bg_right_group)
68left_group.append(bg_left_group)
69
70# add triangle eyes to both groups
71right_group.append(right_pumkin_eye_tilegrid)
72left_group.append(left_pumkin_eye_tilegrid)
73
74# centered vertically
75right_pumkin_eye_tilegrid.y = (SCREEN_SIZE - IMAGE_SIZE) // 2
76left_pumkin_eye_tilegrid.y = (SCREEN_SIZE - IMAGE_SIZE) // 2
77
78while True:
79 # move the eyes to the right
80 for i in range(0, 240 - 173, 5):
81 right_pumkin_eye_tilegrid.x = i
82 left_pumkin_eye_tilegrid.x = i
83 time.sleep(0.01)
84
85 time.sleep(2) # wait 2 seconds
86
87 # move the eyes to the left
88 for i in range(0, 240 - 173, 5):
89 right_pumkin_eye_tilegrid.x -= 5
90 left_pumkin_eye_tilegrid.x -= 5
91 time.sleep(0.01)
92
93 time.sleep(2) # wait 2 seconds
94
95 if mask.boop:
96 pass
97
98 if mask.buttons["S9"]:
99 pass
100
101 if mask.buttons["S10"]:
102 pass
103
104 if mask.buttons["S11"]:
105 pass