jst2_label = funhouse.add_text(text="SENSOR 2", text_position=(40, 95), text_color=0x606060) jst3_label = funhouse.add_text(text="SENSOR 3", text_position=(40, 110), text_color=0x606060) temp_label = funhouse.add_text(text="Temp:", text_position=(50, 45), text_color=0xFF00FF) pres_label = funhouse.add_text(text="Pres:", text_position=(50, 60), text_color=0xFF00FF) funhouse.display.show(funhouse.splash) while True: funhouse.set_text("Temp %0.1F" % funhouse.peripherals.temperature, temp_label) funhouse.set_text("Pres %d" % funhouse.peripherals.pressure, pres_label) print(funhouse.peripherals.temperature, funhouse.peripherals.relative_humidity) set_label_color(funhouse.peripherals.captouch6, onoff_label, 0x00FF00) set_label_color(funhouse.peripherals.captouch7, capleft_label, 0x00FF00) set_label_color(funhouse.peripherals.captouch8, capright_label, 0x00FF00) slider = funhouse.peripherals.slider if slider is not None: funhouse.peripherals.dotstars.brightness = slider funhouse.set_text("Slider: %1.1f" % slider, slider_label) set_label_color(slider is not None, slider_label, 0xFFFF00) set_label_color(funhouse.peripherals.button_up, up_label, 0xFF0000)
reset_label = funhouse.add_text(text="reset", text_position=(3, 70), text_color=GRAY) funhouse.display.show(funhouse.splash) def send_io_data(mail_value): funhouse.peripherals.led = True funhouse.network.push_to_io("mail", mail_value) funhouse.peripherals.led = False send_io_data(1) while True: beam_sensor.update() if beam_sensor.fell: funhouse.peripherals.set_dotstars(RED, WHITE, BLUE, WHITE, RED) funhouse.peripherals.play_tone(2000, 0.25) funhouse.set_text("Mail is here!", mail_label) funhouse.set_text_color(BLUE, mail_label) send_io_data(0) if funhouse.peripherals.button_down: funhouse.peripherals.dotstars.fill(AMBER) funhouse.set_text("No Mail yet", mail_label) funhouse.set_text_color(AMBER, mail_label) send_io_data(1)
# Initialize a new MQTT Client object funhouse.network.init_mqtt( secrets["mqtt_broker"], secrets["mqtt_port"], secrets["mqtt_username"], secrets["mqtt_password"], ) funhouse.network.on_mqtt_connect = connected funhouse.network.on_mqtt_disconnect = disconnected print("Attempting to connect to {}".format(secrets["mqtt_broker"])) funhouse.network.mqtt_connect() last_reading_timestamp = None last_bowl_state = None while True: if last_reading_timestamp is None or time.monotonic( ) > last_reading_timestamp + UPDATE_INTERVAL: # Take Reading water_level = get_bowl_reading() # Update Display funhouse.set_text(bowl_level_display(water_level), level_label) # If changed, publish new result bowl_state = get_bowl_state(water_level) if bowl_state != last_bowl_state: publish_bowl_state(bowl_state) last_bowl_state = bowl_state last_reading_timestamp = time.monotonic()
time.sleep(2) # fumes variable for reading from SGP30 # comment out either TVOC or eCO2 depending on data preference fumes = sgp30.TVOC # fumes = sgp30.eCO2 # mapping fumes data to fan RPM # value for TVOC mapped_val = simpleio.map_range(fumes, 10, 1000, 10, 100) # value for eCO2 # mapped_val = simpleio.map_range(fumes, 400, 2500, 10, 100) # adding fume text # PPB is for TVOC, PPM is for eCO2 funhouse.set_text("%d PPB" % fumes, fume_text) # funhouse.set_text("%d PPM" % fumes, fume_text) # adding fan's RPM text funhouse.set_text("%d%s" % (mapped_val, "%"), fan_text) # printing fan's data to the REPL print("fan = ", mapped_val) # setting fan's RPM emc.manual_fan_speed = int(mapped_val) # if you're connected to wifi and 15 seconds has passed if connected and ((clock + 15) < time.monotonic()): # send fume data to adafruit.io send_fume_data(fumes) # send fan RPM to adafruit.io send_fan_data(mapped_val)
jst2_label = funhouse.add_text(text="SENSOR 2", text_position=(40, 95), text_color=0x606060) jst3_label = funhouse.add_text(text="SENSOR 3", text_position=(40, 110), text_color=0x606060) temp_label = funhouse.add_text(text="Temp:", text_position=(50, 45), text_color=0xFF00FF) pres_label = funhouse.add_text(text="Pres:", text_position=(50, 60), text_color=0xFF00FF) funhouse.display.show(funhouse.splash) while True: funhouse.set_text("Temp %0.1F" % dps310.temperature, temp_label) funhouse.set_text("Pres %d" % dps310.pressure, pres_label) print(aht20.temperature, aht20.relative_humidity) set_label_color(funhouse.peripherals.captouch6, onoff_label, 0x00FF00) set_label_color(funhouse.peripherals.captouch7, capleft_label, 0x00FF00) set_label_color(funhouse.peripherals.captouch8, capright_label, 0x00FF00) slider = funhouse.peripherals.slider if slider is not None: funhouse.peripherals.dotstars.brightness = slider funhouse.set_text("Slider: %1.1f" % slider, slider_label) set_label_color(slider is not None, slider_label, 0xFFFF00) set_label_color(funhouse.peripherals.button_up, up_label, 0xFF0000) set_label_color(funhouse.peripherals.button_sel, sel_label, 0xFFFF00)
funhouse.splash.append(status) # Initialize a new MQTT Client object if USE_MQTT: funhouse.network.init_mqtt( secrets["mqtt_broker"], secrets["mqtt_port"], secrets["mqtt_username"], secrets["mqtt_password"], ) funhouse.network.on_mqtt_connect = connected funhouse.network.on_mqtt_disconnect = disconnected funhouse.network.on_mqtt_message = message print("Attempting to connect to {}".format(secrets["mqtt_broker"])) funhouse.network.mqtt_connect() set_outlet_state(False) while True: if funhouse.peripherals.pir_sensor: last_pir_timestamp = time.monotonic() if not outlet.value: set_outlet_state(True) if outlet.value and time.monotonic( ) >= last_pir_timestamp + MOTION_TIMEOUT: set_outlet_state(False) funhouse.set_text(timeleft(), countdown_label) # Check any topics we are subscribed to if USE_MQTT: funhouse.network.mqtt_loop(0.5)
print("Turning on light...") lifx.toggle_light(lifx_light) # Set the light's brightness light_brightness = 0.65 lifx.set_brightness(lifx_light, light_brightness) lifx.set_color( lifx_light, power="on", color=default_bulb_color, brightness=light_brightness ) while True: if funhouse.peripherals.button_up: trip_time = trip_time + 1 funhouse.set_text(trip_time, time_label) funhouse.set_text_color(0xFFFFFF, up_label) time.sleep(0.2) else: funhouse.set_text_color(0x606060, up_label) if funhouse.peripherals.button_sel: trip_time = abs(trip_time - 1) funhouse.set_text(trip_time, time_label) funhouse.set_text_color(0xFFFFFF, down_label) time.sleep(0.2) else: funhouse.set_text_color(0x606060, down_label) if funhouse.peripherals.button_down: if running_state is False: # it's currently paused, so unpause it