def Screen(backlight_control=True, baudrate=100000000, spi=None):
    """__init__
    :param bool backlight_control: determines whether this class should handle the screen's backlight (default True)
    (this is useful to set to False if you want to control the brightness with pwm in your own code)
    :param int baudrate: sets the baudrate for the spi connection to the display (default 100000000)
    (baudrate doesn't need to be this high for the display to function, it's just nice to have a quick screen refresh by default)
    This class is used to setup the envirowing screen with displayio and return a display object
    """

    import board
    import pimoroni_physical_feather_pins
    import displayio
    from adafruit_st7735r import ST7735R

    # if not supplied an spi object, make our own
    if not spi:
        spi = board.SPI()  # define which spi bus the screen is on

    spi.try_lock()  # try to get control of the spi bus
    spi.configure(
        baudrate=baudrate)  # tell the spi bus how fast it's going to run
    spi.unlock()  # unlocks the spi bus so displayio can control it

    displayio.release_displays(
    )  # release any displays that may exist from previous code run

    if backlight_control:
        display_bus = displayio.FourWire(
            spi,
            command=pimoroni_physical_feather_pins.pin19(),
            chip_select=pimoroni_physical_feather_pins.pin20(),
            reset=pimoroni_physical_feather_pins.pin21(
            ))  # define the display bus
    else:
        display_bus = displayio.FourWire(
            spi,
            command=pimoroni_physical_feather_pins.pin19(),
            chip_select=pimoroni_physical_feather_pins.pin20(
            ))  # define the display bus

    display = ST7735R(
        display_bus,
        width=160,
        height=80,
        colstart=26,
        rowstart=1,
        rotation=270,
        invert=True
    )  # define the display (these values are specific to the envirowing's screen)

    return display
Exemple #2
0
def display_results(tests):
    import board, pimoroni_physical_feather_pins, displayio
    from adafruit_st7735r import ST7735R
    #region Screen setup
    """
    This region of code is used to setup the envirowing screen with displayio
    """

    spi = board.SPI() # define which spi bus the screen is on
    spi.try_lock() # try to get control of the spi bus
    spi.configure(baudrate=100000000) # tell the spi bus how fast it's going to run
    # baudrate doesn't need to be this high in practice, it's just nice to have a quick screen refresh in this case
    spi.unlock() # unlocks the spi bus so displayio can control it
    tft_dc = pimoroni_physical_feather_pins.pin19() # define which pin the command line is on
    tft_cs = pimoroni_physical_feather_pins.pin20() # define which pin the chip select line is on

    displayio.release_displays() # release any displays that may exist from previous code run
    display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=pimoroni_physical_feather_pins.pin21()) # define the display bus

    display = ST7735R(display_bus, width=160, height=80, colstart=26, rowstart=1, rotation=270, invert=True) # define the display (these values are specific to the envirowing's screen)
    
    #endregion Screen setup

    failed = []
    for test in tests.keys():
        if test not in ("Finished", "Read"):
            if not tests[test]["Passed"]:
                failed.append(test)
    
    if not failed:
        print("All Tests Passed!")
    else:
        print("These tests failed:")
        print(", ".join(failed))
    tests["Read"] = True
    write_tests_to_nvm(tests, num_test_bytes)
    while True:
        pass
import pimoroni_physical_feather_pins
from pimoroni_envirowing import screen

# set up the screen and tell it we want to handle the backlight ourselves
screen = screen.Screen(backlight_control=False)

# define a remap function to scale a value from an old range to a new range, preserving ratio
def remap(Value, OldMin,OldMax, NewMin, NewMax):
    return (((Value - OldMin) * (NewMax - NewMin)) / (OldMax - OldMin)) + NewMin

# set up connection with the sensor
i2c_dev = not_SMBus()
ltr559 = LTR559(i2c_dev=i2c_dev)

# define our pwm pin (for changing the screen brightness)
pwm = pulseio.PWMOut(pimoroni_physical_feather_pins.pin21())

try:
    while True:
        # take readings
        lux = ltr559.get_lux()
        prox = ltr559.get_proximity()

        # change screen brightness according to the amount of light detected
        pwm.duty_cycle = int(min(remap(lux, 0, 400, 3, (2**16 - 1)), (2**16 - 1)))

        print("Lux: {:06.2f}, Proximity: {:04d}".format(lux, prox))

        time.sleep(0.05)
except KeyboardInterrupt:
    pass
Exemple #4
0
spi.configure(
    baudrate=100000000)  # tell the spi bus how fast it's going to run
# baudrate doesn't need to be this high in practice, it's just nice to have a quick screen refresh in this case
spi.unlock()  # unlocks the spi bus so displayio can control it
tft_dc = pimoroni_physical_feather_pins.pin19(
)  # define which pin the command line is on
tft_cs = pimoroni_physical_feather_pins.pin20(
)  # define which pin the chip select line is on

displayio.release_displays(
)  # release any displays that may exist from previous code run
display_bus = displayio.FourWire(
    spi,
    command=tft_dc,
    chip_select=tft_cs,
    reset=pimoroni_physical_feather_pins.pin21())  # define the display bus

display = ST7735R(
    display_bus,
    width=160,
    height=80,
    colstart=26,
    rowstart=1,
    rotation=270,
    invert=True
)  # define the display (these values are specific to the envirowing's screen)

print("Screen successfully set up!")

#endregion Screen setup