__init__.py 587 Bytes
Newer Older
1 2
import os
import display
3
import time
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
import buttons
import light_sensor
import math

WIDTH = 160
HEIGHT = 80

disp = display.open()

light_sensor.start()

history = []

while True:
    disp.clear()

    value = light_sensor.get_reading()

    history.insert(0, value)
    if len(history) > WIDTH:
        history.pop()

    disp.print("%i" % value)

    for i in range(0, len(history)):
        # Rescale to range 0 <= value < HEIGHT-1
        y = math.floor(history[i] * (HEIGHT - 2) / max(history))

        disp.pixel(WIDTH - i, HEIGHT - y - 1)

    disp.update()
35
    time.sleep(0.1)