import time import pulseio from pimoroni_ltr559 import LTR559 from pimoroni_circuitpython_adapter import not_SMBus 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))
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ from pimoroni_envirowing import screen display = screen.Screen() import displayio, terminalio from adafruit_display_text import label # Make the display context splash = displayio.Group(max_size=10) display.show(splash) color_bitmap = displayio.Bitmap(160, 80, 1) color_palette = displayio.Palette(1) color_palette[0] = 0x00FF00 # Bright Green bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0,
def __init__(self, colours, bg_colour=None, max_value=None, min_value=None, display=None, top_space=None, width=None, height=None, extra_data=16, auto_show=True, auto_discard=True): """__init__ :param list colours: a list of colours to use for data lines :param int bg_colour: a background colour to use (default black) :param int max_value: the max value to show on the plotter (the top) :param int min_value: the min value to show on the plotter (the bottom) :param display: a supplied display object (creates one if not supplied) :param int top_space: the number of pixels in height to reserve for titles and labels (and not draw lines in) :param int width: the width in pixels of the plot (uses display width if not supplied) :param int height: the height in pixels of the plot (uses display width if not supplied) :param int extra_data: the number of updates that can be applied before a draw (16 if not supplied) :param bool auto_show: invoke show on the displayio object here and per execution of draw() (default True) :param bool auto_discard: discard values which would over fill data_points (True) """ import displayio if not display: from pimoroni_envirowing import screen self.display = screen.Screen() else: self.display = display self.num_colours = len(colours) + 1 plot_width = self.display.width if width is None else width plot_height = self.display.height if height is None else height if top_space: self.bitmap = displayio.Bitmap(plot_width, plot_height - top_space, self.num_colours) self.top_offset = top_space else: self.bitmap = displayio.Bitmap(plot_width, plot_height, self.num_colours) self.top_offset = 0 self.palette = displayio.Palette(self.num_colours) if bg_colour: self.palette[0] = bg_colour else: self.palette[0] = 0x000000 # black for i, j in enumerate(colours): self.palette[i + 1] = j self.tile_grid = displayio.TileGrid(self.bitmap, pixel_shader=self.palette, y=self.top_offset) self.group = displayio.Group() self.group.append(self.tile_grid) self.auto_show = auto_show if self.auto_show: self.display.show(self.group) if max_value: self.max_value = max_value else: self.max_value = 2**16 - 1 # max 16 bit value (unsigned) if min_value: self.min_value = min_value else: self.min_value = 0 # min 16 bit value (unsigned) self.value_range = self.max_value - self.min_value # the extra list element is a gap used for this implementation # of a circular buffer self.data_len = plot_width + extra_data + 1 self.data_points = [None] * self.data_len self.data_head = 0 self.data_tail = 0 self.display_tail = 0 self.displayed_points = 0 self.auto_discard = auto_discard
def __init__(self, colours, bg_colour=None, max_value=None, min_value=None, display=None, top_space=None): """__init__ :param list colours: a list of colours to use for data lines :param int bg_colour: a background colour to use (default black) :param int max_value: the max value to show on the plotter (the top) :param int min_value: the min value to show on the plotter (the bottom) :param display: a supplied display object (creates one if not supplied) :param int top_space: the number of pixels in height to reserve for titles and labels (and not draw lines in) """ import displayio if not display: from pimoroni_envirowing import screen self.display = screen.Screen() else: self.display = display self.num_colours = len(colours) + 1 if top_space: self.bitmap = displayio.Bitmap(160, 80 - top_space, self.num_colours) self.top_offset = top_space else: self.bitmap = displayio.Bitmap(160, 80, self.num_colours) self.top_offset = 0 self.palette = displayio.Palette(self.num_colours) if bg_colour: self.palette[0] = bg_colour else: self.palette[0] = 0x000000 # black for i, j in enumerate(colours): self.palette[i + 1] = j self.tile_grid = displayio.TileGrid(self.bitmap, pixel_shader=self.palette, y=self.top_offset) self.group = displayio.Group(max_size=12) self.group.append(self.tile_grid) self.display.show(self.group) if max_value: self.max_value = max_value else: self.max_value = 2**16 - 1 # max 16 bit value (unsigned) if min_value: self.min_value = min_value else: self.min_value = 0 # min 16 bit value (unsigned) self.value_range = self.max_value - self.min_value self.data_points = []
pressure_feed = io.create_new_feed("pressure") humidity_feed = io.create_new_feed("humidity") # set up the connection with the bme280 i2c = busio.I2C(board.SCL, board.SDA) bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x76) # average global sea level pressure, for more accurate readings change this to your local sea level pressure (measured in hPa) bme280.sea_level_pressure = 1023.50 # set up connection with the ltr559 i2c_dev = not_SMBus(I2C=i2c) ltr559 = LTR559(i2c_dev=i2c_dev) # setup screen screen = screen.Screen(backlight_control=False, spi=spi) # define our pwm pin (for changing the screen brightness) pwm = pulseio.PWMOut(pimoroni_physical_feather_pins.pin21()) # start the screen at 50% brightness pwm.duty_cycle = 2**15 # set up mic input #mic = analogio.AnalogIn(pimoroni_physical_feather_pins.pin8()) # colours for the plotter are defined as rgb values in hex, with 2 bytes for each colour red = 0xFF0000 green = 0x00FF00 blue = 0x0000FF