Ejemplo n.º 1
0
    # get data from the si7021 sensor
    temperature_data = sensor.temperature
    humidity_data = sensor.relative_humidity

    # send data to adafruit io
    print('> Temperature: ', int((temperature_data * 1.8) + 32))
    aio.send(temperature.key, int(temperature_data * 1.8) + 32)
    print('> Humidity :', int(humidity_data))
    aio.send(temperature.key, int(humidity_data))

    # get the indoor light color picker feed
    indoor_light_data = aio.receive(indoor_lights.key)
    print('< Indoor Light HEX: ', indoor_light_data.value)
    # convert the hex values to RGB values
    red = aio.toRed(indoor_light_data.value)
    green = aio.toGreen(indoor_light_data.value)
    blue = aio.toBlue(indoor_light_data.value)

    # set the jewel's color
    for i in range(JEWEL_PIXEL_COUNT):
        pixels[i] = (red, green, blue)
        pixels.show()

    # get the outdoor light color picker feed
    outdoor_light_data = aio.receive(outdoor_lights.key)
    print('< Outdoor Light HEX: ', outdoor_light_data.value)

    # convert the hex values to RGB values
    red = aio.toRed(outdoor_light_data.value)
    green = aio.toGreen(outdoor_light_data.value)
    blue = aio.toBlue(outdoor_light_data.value)
Ejemplo n.º 2
0
def map_range(x, in_min, in_max, out_min, out_max):
    """re-maps a number from one range to another."""
    mapped = (x-in_min) * (out_max - out_min) / (in_max-in_min) + out_min
    if out_min <= out_max:
        return max(min(mapped, out_max), out_min)
    return min(max(mapped, out_max), out_min)

while True:
    # grab the `color` feed
    color_val = aio.receive(color.key)
    if color_val != prev_color:
        # print rgb values and hex value
        print('Received Color: ')
        red = aio.toRed(color_val.value)
        print('\t - R: ', red)
        green = aio.toGreen(color_val.value)
        print('\t - G: ', green)
        blue = aio.toBlue(color_val.value)
        print('\t - B: ', blue)
        print('\t - HEX: ', color_val.value)
        # map color values (0-255) to  16-bit values for the pca
        red = map_range(int(red), 0, 255, 0, 65535)
        green = map_range(int(green), 0, 255, 0, 65535)
        blue = map_range(int(blue), 0, 255, 0, 65535)
        # invert RGB values for common anode LEDs.
        pca.channels[RED_PIN].duty_cycle = 65535 - int(red)
        pca.channels[GREEN_PIN].duty_cycle = 65535 - int(green)
        pca.channels[BLUE_PIN].duty_cycle = 65535 - int(blue)
    prev_color = color_val
    # let's wait a bit so we don't flood adafruit io's servers...
    time.sleep(1)
Ejemplo n.º 3
0
    """re-maps a number from one range to another."""
    mapped = (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
    if out_min <= out_max:
        return max(min(mapped, out_max), out_min)
    return min(max(mapped, out_max), out_min)


while True:
    # grab the `color` feed
    color_val = aio.receive(color.key)
    if color_val != prev_color:
        # print rgb values and hex value
        print('Received Color: ')
        red = aio.toRed(color_val.value)
        print('\t - R: ', red)
        green = aio.toGreen(color_val.value)
        print('\t - G: ', green)
        blue = aio.toBlue(color_val.value)
        print('\t - B: ', blue)
        print('\t - HEX: ', color_val.value)
        # map color values (0-255) to  16-bit values for the pca
        red = map_range(int(red), 0, 255, 0, 65535)
        green = map_range(int(green), 0, 255, 0, 65535)
        blue = map_range(int(blue), 0, 255, 0, 65535)
        # invert RGB values for common anode LEDs.
        pca.channels[RED_PIN].duty_cycle = 65535 - int(red)
        pca.channels[GREEN_PIN].duty_cycle = 65535 - int(green)
        pca.channels[BLUE_PIN].duty_cycle = 65535 - int(blue)
    prev_color = color_val
    # let's wait a bit so we don't flood adafruit io's servers...
    time.sleep(1)