Now did it really...
This commit is contained in:
78
example/lcd_big_hello.py
Normal file
78
example/lcd_big_hello.py
Normal file
@@ -0,0 +1,78 @@
|
||||
"""
|
||||
An example "program" which can be used with the ProgramChooser library, see also main.py
|
||||
Copyright (C) 2024 Benjamin Burkhardt <bluefox@privacynerd.de>
|
||||
|
||||
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/>.
|
||||
"""
|
||||
|
||||
"""
|
||||
@ Feature: Fades "HELLO" over two lines in and out
|
||||
"""
|
||||
|
||||
import machine
|
||||
from machine import I2C, Pin
|
||||
from PCF8574 import I2C_LCD
|
||||
import time
|
||||
|
||||
I2C_ADDR = 0x27
|
||||
I2C_NUM_ROWS = 2
|
||||
I2C_NUM_COLS = 16
|
||||
|
||||
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
|
||||
lcd = I2C_LCD(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS)
|
||||
|
||||
lcd.custom_char(0, bytearray([0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03])) # right
|
||||
lcd.custom_char(1, bytearray([0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18])) # left
|
||||
lcd.custom_char(2, bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F])) # 2-down
|
||||
lcd.custom_char(3, bytearray([0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00])) # 2-up
|
||||
lcd.custom_char(4, bytearray([0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x1F])) # e-up
|
||||
lcd.custom_char(5, bytearray([0x1F,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F])) # e-down
|
||||
lcd.custom_char(6, bytearray([0x18,0x18,0x18,0x18,0x18,0x18,0x1F,0x1F])) # l-down
|
||||
lcd.custom_char(7, bytearray([0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x18])) # l-right
|
||||
|
||||
line1 = str(chr(0) + chr(2) + chr(1) + chr(0) + chr(4) + " " + chr(1) + " " + chr(1) + " " + chr(0) + chr(3) + chr(1))
|
||||
line2 = str(chr(0) + chr(3) + chr(1) + chr(0) + chr(5) + " " + chr(6) + chr(7) + chr(6) + chr(7) + chr(0) + chr(2) + chr(1))
|
||||
|
||||
|
||||
def right2left(line1, line2, speed=0.3):
|
||||
padding = " " # 16 spaces
|
||||
line2 = padding + line2 + padding
|
||||
line1 = padding + line1 + padding
|
||||
for i in range(32):
|
||||
line2 = line2[1:]
|
||||
line1 = line1[1:]
|
||||
lcd.putstr(line1[0:16] + line2[0:16])
|
||||
time.sleep(speed)
|
||||
|
||||
|
||||
def top2bottom(line1, line2, speed=0.2):
|
||||
lcd.clear()
|
||||
time.sleep(speed)
|
||||
lcd.putstr(line2)
|
||||
time.sleep(speed)
|
||||
lcd.clear()
|
||||
lcd.putstr(line1)
|
||||
lcd.move_to(0,1)
|
||||
lcd.putstr(line2)
|
||||
time.sleep(speed)
|
||||
lcd.clear()
|
||||
lcd.move_to(0,1)
|
||||
lcd.putstr(line1)
|
||||
time.sleep(speed)
|
||||
lcd.clear()
|
||||
time.sleep(speed)
|
||||
|
||||
def run(): # for the ProgramChooser as callback
|
||||
right2left(line1, line2, 0.1)
|
||||
top2bottom(line1, line2)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
while True:
|
||||
right2left(line1, line2, 0.1)
|
||||
top2bottom(line1, line2)
|
||||
|
27
example/main.py
Normal file
27
example/main.py
Normal file
@@ -0,0 +1,27 @@
|
||||
"""
|
||||
An example main.py which makes use of the ProgramChooser library
|
||||
Copyright (C) 2024 Benjamin Burkhardt <bluefox@privacynerd.de>
|
||||
|
||||
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/>.
|
||||
"""
|
||||
|
||||
from ProgramChooser import ProgramChooser
|
||||
|
||||
def randomblink():
|
||||
import randomblink
|
||||
randomblink.run()
|
||||
def lcd_big_hello():
|
||||
import lcd_big_hello
|
||||
lcd_big_hello.run()
|
||||
|
||||
programs = {
|
||||
"randomblink": randomblink,
|
||||
"lcd_big_hello": lcd_big_hello
|
||||
}
|
||||
|
||||
pc = ProgramChooser(programs, 7, 8, debug=True)
|
||||
pc.run()
|
48
example/randomblink.py
Normal file
48
example/randomblink.py
Normal file
@@ -0,0 +1,48 @@
|
||||
"""
|
||||
An example "program" which can be used with the ProgramChooser library, see also main.py
|
||||
Copyright (C) 2024 Benjamin Burkhardt <bluefox@privacynerd.de>
|
||||
|
||||
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/>.
|
||||
"""
|
||||
|
||||
"""
|
||||
# Feature: blink pico's onboard led (GPIO25) randomly
|
||||
"""
|
||||
|
||||
from machine import Pin
|
||||
from time import sleep
|
||||
import random
|
||||
|
||||
def run():
|
||||
# Initialisierung von GPIO25 als Ausgang
|
||||
led_onboard = Pin(25, Pin.OUT)
|
||||
pause_counter = 0
|
||||
counter = 0
|
||||
|
||||
# repeat for some time (as it's randomly you don't really now)
|
||||
# approx ~30s
|
||||
while counter < 30:
|
||||
# turn LED on
|
||||
led_onboard.on()
|
||||
# wait a short time (80ms)
|
||||
sleep(0.08)
|
||||
# turn LED off
|
||||
led_onboard.off()
|
||||
# wait a shorter time (20ms)
|
||||
sleep(0.02)
|
||||
pause_counter += 1
|
||||
|
||||
# make a pause (1s) randomly
|
||||
if pause_counter > random.randint(6,20):
|
||||
sleep(1)
|
||||
|
||||
print(counter)
|
||||
counter += 1
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
|
Reference in New Issue
Block a user