Simple test¶
Ensure your device works with this simple test.
1# SPDX-FileCopyrightText: 2019 Dave Astels for Adafruit Industries
2# SPDX-License-Identifier: MIT
3"""Example of using save_bitmap"""
4# pylint:disable=invalid-name
5
6import board
7import busio
8import digitalio
9from displayio import Bitmap, Palette
10import adafruit_sdcard
11import storage
12from adafruit_bitmapsaver import save_pixels
13
14TAKE_SCREENSHOT = False # Set True to take a screenshot
15
16WHITE = 0xFFFFFF
17BLACK = 0x000000
18RED = 0xFF0000
19ORANGE = 0xFFA500
20YELLOW = 0xFFFF00
21GREEN = 0x00FF00
22BLUE = 0x0000FF
23PURPLE = 0x800080
24PINK = 0xFFC0CB
25
26colors = (BLACK, RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE, WHITE)
27
28print("Building sample bitmap and palette")
29bitmap = Bitmap(16, 16, 9)
30palette = Palette(len(colors))
31for i, c in enumerate(colors):
32 palette[i] = c
33
34for x in range(16):
35 for y in range(16):
36 if x == 0 or y == 0 or x == 15 or y == 15:
37 bitmap[x, y] = 1
38 elif x == y:
39 bitmap[x, y] = 4
40 elif x == 15 - y:
41 bitmap[x, y] = 5
42 else:
43 bitmap[x, y] = 0
44
45if TAKE_SCREENSHOT:
46 # Initialize SD Card & Mount Virtual File System
47 print("Setting up SD card")
48 spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
49 cs = digitalio.DigitalInOut(board.SD_CS)
50 sdcard = adafruit_sdcard.SDCard(spi, cs)
51 vfs = storage.VfsFat(sdcard)
52 storage.mount(vfs, "/sd") # /sd is root dir of SD Card
53
54 print("Taking Screenshot... ")
55 save_pixels("/sd/screenshot.bmp", bitmap, palette)
56 print("Screenshot Saved")
57 storage.umount(vfs)
58 print("SD Card Unmounted") # Do not remove SD card until unmounted
1# SPDX-FileCopyrightText: 2019 Dave Astels for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4"""Example of taking a screenshot."""
5
6# pylint:disable=invalid-name
7import board
8import digitalio
9import busio
10import adafruit_sdcard
11import storage
12from adafruit_bitmapsaver import save_pixels
13
14TAKE_SCREENSHOT = False # Set to True to take a screenshot
15
16if TAKE_SCREENSHOT:
17 # Initialize SD Card & Mount Virtual File System
18 spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
19 cs = digitalio.DigitalInOut(board.SD_CS)
20 sdcard = adafruit_sdcard.SDCard(spi, cs)
21 vfs = storage.VfsFat(sdcard)
22 storage.mount(vfs, "/sd") # /sd is root dir of SD Card
23
24 print("Taking Screenshot... ")
25 save_pixels("/sd/screenshot.bmp")
26 print("Screenshot Saved")
27 storage.umount(vfs)
28 print("SD Card Unmounted") # Do not remove SD card until unmounted