Im Mai/Juni 2022
Wie lange arbeite ich? Kann ich da nicht auch was bauen, um das zu messen?
Großer Knopf = Start / Stop
Kleiner Knopf = Reset
Aufbau:
Das Programm in MicroPython:
import time
from machine import I2C, Pin, Timer
from I2C_LCD import I2CLcd
i2c = I2C(1, sda=Pin(14), scl=Pin(15), freq=400000)
devices = i2c.scan()
timer = Timer()
count = 0;
pause = False
def tick(timer):
global count
global buttonPause
global buttonReset
if (not pause):
count = count + 1
lcd.clear();
lcd.move_to(0, 0)
if (not pause):
lcd.putstr("\x02 Laeuft")
else:
lcd.putstr("\x01 Pause")
lcd.move_to(0, 1)
lcd.putstr("%dmin %ds" %(count // 60, count % 60))
def button_handler(pin):
if (pin.value() == 1): # only if pressed, not on release
if pin == buttonPause:
button_handlerPause(pin)
else:
button_handlerReset(pin)
def button_handlerReset(pin):
global count;
count = 0;
#print("Button (%s) changed to: %r" % (pin, pin.value()))
def button_handlerPause(pin):
global pause
pause = not pause
#print("Button (%s) changed to: %r" % (pin, pin.value()))
buttonPause = Pin(12, Pin.IN, Pin.PULL_DOWN)
buttonPause.irq(trigger = machine.Pin.IRQ_RISING, handler = button_handler)
buttonReset = Pin(13, Pin.IN, Pin.PULL_DOWN)
buttonReset.irq(trigger = machine.Pin.IRQ_RISING, handler = button_handler)
try:
if devices != []:
lcd = I2CLcd(i2c, devices[0], 2, 16)
# custom symbols
symbolRun = [
0b00000,
0b01110,
0b10101,
0b10111,
0b10001,
0b01110,
0b00000,
0b00000
]
lcd.custom_char(1, symbolRun)
symbolSand = [
0b11111,
0b10001,
0b10001,
0b01010,
0b00100,
0b01110,
0b11111,
0b11111
]
lcd.custom_char(2, symbolSand)
timer.init(freq=1, mode=Timer.PERIODIC, callback=tick)
else:
print("No address found")
except:
pass
Benötigt werden noch zwei Bibliotheken:
./I2C_LCD.py
./LCD_API.py