esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2)
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)

# Initialize PyPortal Display
display = board.DISPLAY

WIDTH = board.DISPLAY.width
HEIGHT = board.DISPLAY.height

# Initialize new PyPortal object
pyportal = PyPortal(esp=esp,
                    external_spi=spi)

# Set backlight level
pyportal.set_backlight(0.5)

# Create a new DisplayIO group
splash = displayio.Group(max_size=15)

# show splash group
display.show(splash)

# Palette for water bitmap
palette = displayio.Palette(2)
palette[0] = 0x000000
palette[1] = WATER_COLOR
palette.make_transparent(0)

# Create water bitmap
water_bmp = displayio.Bitmap(display.width, display.height, len(palette))
示例#2
0
WHITE = (0, 0, 0, 255)
# number of minutes it takes for strip to fade from min to max
light_minutes = 30

# determine the current working directory
# needed so we know where to find files
cwd = ("/" + __file__).rsplit('/', 1)[0]

# initialize the pyportal object and let us know what data to fetch and where
# to display it
pyportal = PyPortal(status_neopixel=board.NEOPIXEL, default_bg=0x000000)

# set backlight default to off
backlight_off = 0
backlight_on = 0.8
pyportal.set_backlight(backlight_off)

# assign fonts
big_font = bitmap_font.load_font(cwd + "/fonts/Nunito-Light-75.bdf")
big_font.load_glyphs(b'0123456789:AP')  # pre-load glyphs for fast printing
print('loading fonts...')
info_font = bitmap_font.load_font(cwd + "/fonts/Nunito-Black-17.bdf")
info_font.load_glyphs(
    b'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-,.:/ ')

time_color = 0xFFFFFF
time_position = (75, 130)
time_textarea = Label(big_font,
                      max_glyphs=15,
                      color=time_color,
                      x=time_position[0],
示例#3
0
# Set up an analog light sensor on the PyPortal
adc = AnalogIn(board.LIGHT)

localtile_refresh = None
weather_refresh = None
while True:
    print(adc.value)

    # set brightness based on room brightness, min 20% max 80%
    brightnessPercent = adc.value/65536
    if brightnessPercent < .2:
        brightnessPercent = .2
    elif brightnessPercent > .8:
        brightnessPercent = .8

    pyportal.set_backlight(brightnessPercent)

    # only query the online time once per hour (and on first run)
    if (not localtile_refresh) or (time.monotonic() - localtile_refresh) > 3600:
        try:
            pyportal.get_local_time()
            localtile_refresh = time.monotonic()
        except RuntimeError as e:
            print("Some error occured, retrying! -", e)
            continue

    # only query the weather every 10 minutes (and on first run)
    if (not weather_refresh) or (time.monotonic() - weather_refresh) > 600:
        try:
            value = pyportal.fetch()
            print("Response is", value)
    'marvel.bmp',
    'post.bmp',
    'spider.bmp',
    'thor.bmp',
    'vis.bmp',
    'witch.bmp'
]

# the current working directory (where this file is)
cwd = ("/"+__file__).rsplit('/', 1)[0]
pyportal = PyPortal(status_neopixel=board.NEOPIXEL)

# pyportal.play_file(audio)
# speed up projects with lots of text by preloading the font!
pyportal.preload_font()
pyportal.set_backlight(1.00)
i = 0.001

# disp

while True:
    try:

        for image in images:
            pyportal.set_background(image)
            board.DISPLAY.refresh_soon()
            board.DISPLAY.wait_for_frame()
            time.sleep(i)

    except RuntimeError as e:
        print("Some error occured, retrying! -", e)