Simple test

Ensure your device works with this simple test.

examples/bitmapsaver_simpletest.py
 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 adafruit_sdcard
 7import board
 8import busio
 9import digitalio
10import storage
11from displayio import Bitmap, Palette
12
13from adafruit_bitmapsaver import save_pixels
14
15TAKE_SCREENSHOT = False  # Set True to take a screenshot
16
17WHITE = 0xFFFFFF
18BLACK = 0x000000
19RED = 0xFF0000
20ORANGE = 0xFFA500
21YELLOW = 0xFFFF00
22GREEN = 0x00FF00
23BLUE = 0x0000FF
24PURPLE = 0x800080
25PINK = 0xFFC0CB
26
27colors = (BLACK, RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE, WHITE)
28
29print("Building sample bitmap and palette")
30bitmap = Bitmap(16, 16, 9)
31palette = Palette(len(colors))
32for i, c in enumerate(colors):
33    palette[i] = c
34
35for x in range(16):
36    for y in range(16):
37        if x in {0, 15} or y in {0, 15}:
38            bitmap[x, y] = 1
39        elif x == y:
40            bitmap[x, y] = 4
41        elif x == 15 - y:
42            bitmap[x, y] = 5
43        else:
44            bitmap[x, y] = 0
45
46if TAKE_SCREENSHOT:
47    # Initialize SD Card & Mount Virtual File System
48    print("Setting up SD card")
49    spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
50    cs = digitalio.DigitalInOut(board.SD_CS)
51    sdcard = adafruit_sdcard.SDCard(spi, cs)
52    vfs = storage.VfsFat(sdcard)
53    storage.mount(vfs, "/sd")  # /sd is root dir of SD Card
54
55    print("Taking Screenshot... ")
56    save_pixels("/sd/screenshot.bmp", bitmap, palette)
57    print("Screenshot Saved")
58    storage.umount(vfs)
59    print("SD Card Unmounted")  # Do not remove SD card until unmounted
examples/bitmapsaver_screenshot_simpletest.py
 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 adafruit_sdcard
 8import board
 9import busio
10import digitalio
11import storage
12
13from adafruit_bitmapsaver import save_pixels
14
15TAKE_SCREENSHOT = False  # Set to True to take a screenshot
16
17if TAKE_SCREENSHOT:
18    # Initialize SD Card & Mount Virtual File System
19    spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
20    cs = digitalio.DigitalInOut(board.SD_CS)
21    sdcard = adafruit_sdcard.SDCard(spi, cs)
22    vfs = storage.VfsFat(sdcard)
23    storage.mount(vfs, "/sd")  # /sd is root dir of SD Card
24
25    print("Taking Screenshot... ")
26    save_pixels("/sd/screenshot.bmp")
27    print("Screenshot Saved")
28    storage.umount(vfs)
29    print("SD Card Unmounted")  # Do not remove SD card until unmounted