import board from adafruit_debouncer import Debouncer from digitalio import DigitalInOut, Pull from adafruit_funhouse import FunHouse beam_sense_pin = DigitalInOut(board.A0) # defaults to input beam_sense_pin.pull = Pull.UP # turn on internal pull-up resistor beam_sensor = Debouncer(beam_sense_pin) AMBER = 0xF0D000 BLUE = 0x00D0F0 RED = 0xFF0000 WHITE = 0xFFFFFF GRAY = 0x606060 funhouse = FunHouse(default_bg=None, scale=3) funhouse.peripherals.dotstars.brightness = 0.05 funhouse.peripherals.dotstars.fill(AMBER) # Create the labels funhouse.display.show(None) mail_label = funhouse.add_text(text="No Mail yet", text_position=(4, 14), text_color=AMBER) reset_label = funhouse.add_text(text="reset", text_position=(3, 70), text_color=GRAY) funhouse.display.show(funhouse.splash)
import time import board import adafruit_hcsr04 import neopixel from adafruit_funhouse import FunHouse SLOW_DISTANCE = 30 # distance (in centimeters) when you should slow STOP_DISTANCE = 8 # distance when you should hit those brakes GREEN = 0x00FF00 AMBER = 0xF0D000 RED = 0xFF0000 funhouse = FunHouse(default_bg=None, scale=3) funhouse.peripherals.dotstars.brightness = 0.05 funhouse.peripherals.dotstars.fill(GREEN) pixel_pin = board.A2 num_pixels = 30 pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.3, auto_write=False) sonar = adafruit_hcsr04.HCSR04(trigger_pin=board.A0, echo_pin=board.A1) while True: try: print((sonar.distance,)) if sonar.distance > SLOW_DISTANCE: funhouse.peripherals.dotstars.fill(GREEN)
PUBLISH_DELAY = 60 ENVIRONMENT_CHECK_DELAY = 5 ENABLE_PIR = True MQTT_TOPIC = "funhouse/state" LIGHT_STATE_TOPIC = "funhouse/light/state" LIGHT_COMMAND_TOPIC = "funhouse/light/set" INITIAL_LIGHT_COLOR = 0x008000 USE_FAHRENHEIT = True try: from secrets import secrets except ImportError: print("WiFi secrets are kept in secrets.py, please add them there!") raise funhouse = FunHouse(default_bg=0x0F0F00) funhouse.peripherals.dotstars.fill(INITIAL_LIGHT_COLOR) funhouse.display.show(None) funhouse.add_text( text="Temperature:", text_position=(20, 30), text_color=0xFF8888, text_font="fonts/Arial-Bold-24.pcf", ) temp_label = funhouse.add_text( text_position=(120, 60), text_anchor_point=(0.5, 0.5), text_color=0xFFFF00, text_font="fonts/Arial-Bold-24.pcf", )
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries # SPDX-FileCopyrightText: Copyright (c) 2021 Melissa LeBlanc-Williams for Adafruit Industries # # SPDX-License-Identifier: Unlicense import board from digitalio import DigitalInOut, Direction, Pull from adafruit_funhouse import FunHouse funhouse = FunHouse( default_bg=0x0F0F00, scale=2, ) funhouse.peripherals.set_dotstars(0x800000, 0x808000, 0x008000, 0x000080, 0x800080) # sensor setup sensors = [] for p in (board.A0, board.A1, board.A2): sensor = DigitalInOut(p) sensor.direction = Direction.INPUT sensor.pull = Pull.DOWN sensors.append(sensor) def set_label_color(conditional, index, on_color): if conditional: funhouse.set_text_color(on_color, index) else: funhouse.set_text_color(0x606060, index)
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries # SPDX-FileCopyrightText: Copyright (c) 2021 Melissa LeBlanc-Williams for Adafruit Industries # # SPDX-License-Identifier: MIT import time from adafruit_funhouse import FunHouse funhouse = FunHouse(default_bg=None) funhouse.peripherals.set_dotstars(0x800000, 0x808000, 0x008000, 0x000080, 0x800080) # pylint: disable=unused-argument def connected(client): print("Connected to Adafruit IO! Subscribing...") client.subscribe("buzzer") client.subscribe("neopixels") def subscribe(client, userdata, topic, granted_qos): print("Subscribed to {0} with QOS level {1}".format(topic, granted_qos)) def disconnected(client): print("Disconnected from Adafruit IO!") def message(client, feed_id, payload): print("Feed {0} received new value: {1}".format(feed_id, payload)) if feed_id == "buzzer": if int(payload) == 1:
def get_bowl_state(level): if level <= EMPTY_VALUE: return "empty" elif level <= LOW_VALUE: return "low" return "full" def bowl_level_display(water_level): if funhouse.peripherals.button_sel: return water_level return states[get_bowl_state(water_level)] # Set Initial States funhouse = FunHouse(default_bg=0x0F0F00) funhouse.peripherals.dotstars.fill(0) water_enable = digitalio.DigitalInOut(board.A0) water_enable.switch_to_output() water_level_sensor = analogio.AnalogIn(board.A1) funhouse.display.show(None) funhouse.add_text( text="Bowl Level:", text_position=(120, 60), text_anchor_point=(0.5, 0.5), text_color=0xFF0000, text_font="fonts/Arial-Bold-24.pcf", ) level_label = funhouse.add_text( text_position=(120, 100), text_anchor_point=(0.5, 0.5),
i2c = board.I2C() # setup for SGP30 sensor sgp30 = adafruit_sgp30.Adafruit_SGP30(i2c) # setup for fan controller emc = EMC2101(i2c) print("SGP30 serial #", [hex(i) for i in sgp30.serial]) #SGP30 start-up sgp30.iaq_init() sgp30.set_iaq_baseline(0x8973, 0x8AAE) # FunHouse setup funhouse = FunHouse(default_bg=0x0F0F00) # start-up bitmap bitmap, palette = adafruit_imageload.load("/scene1_fume.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette) tile_grid = displayio.TileGrid(bitmap, pixel_shader=palette) # connecting bitmap bitmap2, palette2 = adafruit_imageload.load("/scene2_fume.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette) grid2 = displayio.TileGrid(bitmap2, pixel_shader=palette2) # default background bitmap3, palette3 = adafruit_imageload.load("/scene3_fume.bmp", bitmap=displayio.Bitmap, palette=displayio.Palette) grid3 = displayio.TileGrid(bitmap3, pixel_shader=palette3)
print("Topic {0} received new value: {1}".format(topic, payload)) if topic == OUTLET_COMMAND_TOPIC: set_outlet_state(payload == "on") def timeleft(): seconds = int(last_pir_timestamp + MOTION_TIMEOUT - time.monotonic()) if outlet.value and seconds >= 0: minutes = seconds // 60 seconds -= minutes * 60 return "{:01}:{:02}".format(minutes, seconds) return "Off" # Set Initial States funhouse = FunHouse(default_bg=0x0F0F00) funhouse.peripherals.dotstars.fill(0) outlet = digitalio.DigitalInOut(board.A0) outlet.direction = digitalio.Direction.OUTPUT last_pir_timestamp = None funhouse.display.show(None) funhouse.add_text( text="Timeout Left:", text_position=(20, 60), text_color=0xFF0000, text_font="fonts/Arial-Bold-24.pcf", ) countdown_label = funhouse.add_text( text_position=(120, 100), text_anchor_point=(0.5, 0.5), text_color=0xFFFF00,
# Add your LIFX Personal Access token to secrets.py # (to obtain a token, visit: https://cloud.lifx.com/settings) lifx_token = secrets["lifx_token"] # Set this to your LIFX light separator label # https://api.developer.lifx.com/docs/selectors lifx_light = "label:Lamp" # Initialize the LIFX API Client lifx = adafruit_lifx.LIFX(http_session, lifx_token) # List all lights lights = lifx.list_lights() # print(lights) # uncomment for lots of LIFX light info funhouse = FunHouse(default_bg=0x000F20, scale=3) pir_state = 0 running_state = False trip_time = 30 # seconds to stay tripped, adjust this with buttons while running funhouse.peripherals.dotstars.fill(default_led_color) def set_label_color(conditional, index, on_color): if conditional: funhouse.set_text_color(on_color, index) else: funhouse.set_text_color(0x606060, index)