Beispiel #1
0
p5(True)


def tick(state):
    global LAST, TIME, FLAG
    now = time.ticks_ms()
    if now - LAST > 250:
        TIME = time.ticks_diff(now, LAST)
        LAST = now
        FLAG = True
        print('Now!', LAST, TIME, FLAG)
    # toggle power to the sensor
    # to toggle latch state
    p5(False)
    p5(True)


# configure
p16.irq(tick, machine.Pin.IRQ_RISING)

i2c = machine.I2C(scl=machine.Pin(4), sda=machine.Pin(5))
d = ssd1306.SSD1306(i2c)

while True:
    print(FLAG)
    if FLAG:
        d.fill(0)
        d.text(str(TIME), 0, 0, 1)
        d.show()
        FLAG = False
Beispiel #2
0
import d2
import machine, ssd1306

d = ssd1306.SSD1306(machine.I2C(scl=machine.Pin(4), sda=machine.Pin(5)))

xscale = d2.scale_linear(0, d.width, -2.5, 1, False)
yscale = d2.scale_linear(0, d.height, -1, 1, False)

imax = 10
imax1 = imax + 1
for y in range(d.height):
    y0 = yscale(y)
    for x in range(d.width):
        x0 = xscale(x)
        c = z = complex(x0, y0)
        for i in range(1, imax1):
            if abs(z) > 2:
                break
            z = z * z + c
        if i == imax:
            d.pixel(x, y, 1)

d.show()