コード例 #1
0
def test_set_image_wrap(GPIO, spidev):
    from unicornhatmini import UnicornHATMini
    unicornhatmini = UnicornHATMini()

    image = mock.MagicMock()
    image.size = (3, 3)
    image.mode = "RGB"
    image.getpixel.return_value = (255, 255, 255)
    unicornhatmini.set_image(image, offset_x=0, offset_y=0, wrap=True)
コード例 #2
0
def test_set_image(GPIO, spidev):
    from unicornhatmini import UnicornHATMini
    unicornhatmini = UnicornHATMini()

    image = mock.MagicMock()
    image.size = (17, 7)
    image.getpixel.return_value = (255, 255, 255)
    image.convert.return_value = image
    unicornhatmini.set_image(image, offset_x=0, offset_y=0)

    image.mode = "RGB"
    unicornhatmini.set_image(image, offset_x=0, offset_y=0)
コード例 #3
0
temp_color = 0

settings = {
    'api_key': 'your_key_here',
    'zip_code': '94112',
    'country_code': 'us',
    'temp_unit': 'imperial'
}  #unit can be metric, imperial, or kelvin

BASE_URL = "http://api.openweathermap.org/data/2.5/weather?appid={0}&zip={1},{2}&units={3}"

while True:
    final_url = BASE_URL.format(settings["api_key"], settings["zip_code"],
                                settings["country_code"],
                                settings["temp_unit"])
    weather_data = requests.get(final_url).json()
    temperature = weather_data["main"]["temp"]
    print(temperature)

    temp_color = int(temperature)
    if temperature >= 85:
        image = Image.new("RGB", (17, 7), (255, 0, 0))
    if temperature >= 55 and temperature <= 85:
        image = Image.new("RGB", (17, 7), (0, 255, 0))
    if temperature <= 55:
        image = Image.new("RGB", (17, 7), (0, 0, 255))

    unicornhatmini.set_image(image)
    unicornhatmini.show()
    time.sleep(60)  #get new data every 60 seconds
コード例 #4
0
font = ImageFont.truetype("5x7.ttf", 8)

text_width, text_height = font.getsize(text)

image = Image.new('P',
                  (text_width + display_width + display_width, display_height),
                  0)
draw = ImageDraw.Draw(image)

# Draw the text into the image
draw.text((0, 0), text, font=font, fill=255)

while True:
    final_url = BASE_URL.format(settings["api_key"], settings["zip_code"],
                                settings["country_code"],
                                settings["temp_unit"])
    weather_data = requests.get(final_url).json()
    temperature = weather_data["main"]["temp"]
    print(temperature)

    text = str(temperature)
    image = Image.new(
        'P', (text_width + display_width + display_width, display_height), 0)
    draw = ImageDraw.Draw(image)
    draw.text((0, 0), text, font=font, fill=255)
    unicornhatmini.set_image(image, 0, wrap=True)
    unicornhatmini.show()

    time.sleep(60)  #get new data every 60 seconds
コード例 #5
0
                        continue
                    else:
                        sound_level = ((granularity * value) / max_audioop)
                        # print(str(sound_level))
                        offset_y = 0

                        if sound_level <= 10:
                            image = Image.open("chiusa.png")
                        elif sound_level <= 35:
                            image = Image.open("apri1.png")
                        elif sound_level <= 50:
                            image = Image.open("apri2.png")
                        else:
                            image = Image.open("apri3.png")
                        unicornhatmini.set_image(image,
                                                 offset_y=offset_y,
                                                 wrap=False)
                        unicornhatmini.show()
                        time.sleep(0.001)

    except (KeyboardInterrupt, SystemExit):

        # Clean screen
        image = Image.open("nero.png")
        unicornhatmini.set_image(image, offset_y=0, wrap=False)
        unicornhatmini.show()

        button_a.close()
        button_b.close()
        button_x.close()
        button_y.close()