2023-11-02 18:00:25 +00:00
"""
micronEC : Simple , easy - to - use hardware counter . Raspberry Pico basis . 16 * 2 LCD display . micronEC .
Copyright ( C ) 2023 Benjamin Burkhardt
This program is free software : you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program . If not , see < https : / / www . gnu . org / licenses / > .
"""
2023-11-02 17:01:51 +00:00
from lcd_driver import I2C_LCD
from machine import I2C , Pin
from welcome import WelcomeScreen
from counter import CounterArray
from lcd_screen import CounterScreen
2023-11-02 17:43:55 +00:00
# some constants, change on need
I2C_ADDR = 0x27 # for pico w, this should fit
I2C_NUM_ROWS = 2 # DON'T CHANGE
I2C_NUM_COLS = 16 # DON'T CHANGE
WELCOME_CYCLES = 1 # adjusts how often the "Starting..." runs through at startup
COUNTER_NUMBER = 2 # how many counters do you want?
COUNTER_NAMES = [ " Counter 1 " , " Counter 2 " ] # names of the counters (MUST contain names for all counters)
COUNTER_PINS = { 0 : 2 , 1 : 3 } # which pins to listen on (form {<COUNTER NUMBER STARTING FROM 0>:<GPIO PIN>}) (there MAY be doubles, you MAY not give pins for all counters)
2023-11-02 17:01:51 +00:00
2023-11-02 17:15:49 +00:00
2024-03-09 19:05:08 +00:00
# RUN micronec if it is the main program (not imported)
def run ( ) : # for possible ProgramChooser use
# initialize the lcd display with GPIO pins 0 and 1 for data on i2c channel 0
_i2c = I2C ( 0 , sda = Pin ( 0 ) , scl = Pin ( 1 ) , freq = 400000 )
lcd = I2C_LCD ( _i2c , I2C_ADDR , I2C_NUM_ROWS , I2C_NUM_COLS )
# initialize the counter array (class managing all the counters)
counterArray = CounterArray ( COUNTER_NUMBER , COUNTER_NAMES )
# initialize the welcome screen
ws = WelcomeScreen ( lcd )
# initialize the counter screen (display counter values on lcd)
cs = CounterScreen ( lcd , counterArray )
# Real program
ws . show_welcome ( WELCOME_CYCLES ) # show welcome/startup message
cs . show_screen ( ) # DON'T REMOVE; show counter screen one time, may take up to 15s
counterArray . register_listener ( COUNTER_PINS , cs . show_screen ) # register the listeners on the given pins
while True :
pass
if __name__ == " __main__ " :
run ( )