Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Letters #14

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from apps import App
from display import Display
from rtc import RTC
from buttons import Buttons


class Clock(App):
Expand All @@ -10,12 +11,14 @@ def __init__(self, scheduler):
self.display = Display(scheduler)
self.rtc = RTC()
self.enabled = True
self.buttons = Buttons(scheduler)
scheduler.schedule("clock-second", 1000, self.secs_callback)
scheduler.schedule("clock-minute", 60000, self.mins_callback)

def enable(self):
self.enabled = True
self.update_time()
self.buttons.add_callback(3, self.backlight_callback, max=500)

def disable(self):
self.enabled = False
Expand All @@ -37,3 +40,9 @@ def update_time(self):
now = "%02d:%02d" % (t[3], t[4])
self.display.show_day(t[6])
self.display.show_text(now)
if self.display.auto_backlight:
self.display.show_icon("AutoLight")

def backlight_callback(self, t):
self.display.switch_backlight()

90 changes: 76 additions & 14 deletions display.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from machine import Pin, Timer
from machine import Pin, ADC

from util import singleton

from utime import sleep_us

@singleton
class Display:
Expand All @@ -10,9 +10,13 @@ def __init__(self, scheduler):
self.a1 = Pin(18, Pin.OUT)
self.a2 = Pin(22, Pin.OUT)

self.oe = Pin(13, Pin.OUT)

self.sdi = Pin(11, Pin.OUT)
self.clk = Pin(10, Pin.OUT)
self.le = Pin(12, Pin.OUT)

self.ain = ADC(26)

self.row = 0
self.count = 0
Expand All @@ -21,7 +25,17 @@ def __init__(self, scheduler):
self.disp_offset = 2
self.initialise_fonts()
self.initialise_icons()
scheduler.schedule("enable-leds", 1, self.enable_leds)

self.scheduler = scheduler

# CPU freq needs to be increase to 250 for better results
self.backlight_sleep = [10, 100, 300, 1500] # From 10 (low) to 1500(High)
self.current_backlight = 3
self.auto_backlight = True
self.show_icon("AutoLight")
self.update_auto_backlight_value(None)
self.scheduler.schedule("enable-leds", 1, self.enable_leds)
self.scheduler.schedule("update_auto_backlight_value", 1000, self.update_auto_backlight_value)

def enable_leds(self, t):
self.count += 1
Expand All @@ -39,6 +53,9 @@ def enable_leds(self, t):
self.a0.value(1 if self.row & 0x01 else 0)
self.a1.value(1 if self.row & 0x02 else 0)
self.a2.value(1 if self.row & 0x04 else 0)
self.oe.value(0)
sleep_us(self.backlight_sleep[self.current_backlight])
self.oe.value(1)

def clear(self, x=0, y=0, w=24, h=7):
for yy in range(y, y + h + 1):
Expand Down Expand Up @@ -80,14 +97,39 @@ def hide_icon(self, name):
self.leds[icon.y][icon.x + w] = 0
self.leds_changed = True

def backlight_on(self):
def sidelight_on(self):
self.leds[0][2] = 1
self.leds[0][5] = 1

def backlight_off(self):
def sidelight_off(self):
self.leds[0][2] = 0
self.leds[0][5] = 0

def switch_backlight(self):
if self.auto_backlight:
self.auto_backlight = False
self.hide_icon("AutoLight")
self.current_backlight = 0
self.scheduler.remove("update_auto_backlight_value")
elif self.current_backlight == 3:
self.show_icon("AutoLight")
self.auto_backlight = True
self.update_auto_backlight_value(None)
self.scheduler.schedule("update_auto_backlight_value", 1000, self.update_auto_backlight_value)
else:
self.current_backlight += 1

def update_auto_backlight_value(self, t):
aim = self.ain.read_u16()
if aim > 60000: # Low light
self.current_backlight = 0
elif aim > 58000:
self.current_backlight = 1
elif aim > 40000:
self.current_backlight = 2
else:
self.current_backlight = 3

def print(self):
for row in range(0, 8):
for pos in range(0, 24):
Expand Down Expand Up @@ -173,26 +215,39 @@ def initialise_fonts(self):
"D": self.Character(width=4, rows=[0x07,0x09,0x09,0x09,0x09,0x09,0x07]),
"E": self.Character(width=4, rows=[0x0F,0x01,0x01,0x0F,0x01,0x01,0x0F]),
"F": self.Character(width=4, rows=[0x0F,0x01,0x01,0x0F,0x01,0x01,0x01]),
"G": self.Character(width=4, rows=[0x06,0x09,0x01,0x0D,0x09,0x09,0x06]),
"H": self.Character(width=4, rows=[0x09,0x09,0x09,0x0F,0x09,0x09,0x09]),
"I": self.Character(width=3, rows=[0x07,0x02,0x02,0x02,0x02,0x02,0x07]),
"J": self.Character(width=4, rows=[0x0F,0x08,0x08,0x08,0x09,0x09,0x06]),
"K": self.Character(width=4, rows=[0x09,0x05,0x03,0x01,0x03,0x05,0x09]),
"L": self.Character(width=4, rows=[0x01,0x01,0x01,0x01,0x01,0x01,0x0F]),
"M": self.Character(width=4, rows=[0x00,0x11,0x1B,0x15,0x11,0x11,0x11,0x11]), # 5×7
"N": self.Character(width=4, rows=[0x09,0x09,0x0B,0x0D,0x09,0x09,0x09]),
"O": self.Character(width=4, rows=[0x0F,0x09,0x09,0x09,0x09,0x09,0x0F]),
"O": self.Character(width=4, rows=[0x06,0x09,0x09,0x09,0x09,0x09,0x06]),
"P": self.Character(width=4, rows=[0x07,0x09,0x09,0x07,0x01,0x01,0x01]),
"Q": self.Character(width=5, rows=[0x0E,0x11,0x11,0x11,0x15,0x19,0x0E]),#Q
"R": self.Character(width=4, rows=[0x07,0x09,0x09,0x07,0x03,0x05,0x09]), #R
"S": self.Character(width=4, rows=[0x06,0x09,0x02,0x04,0x08,0x09,0x06]),#S
"T": self.Character(width=5, rows=[0x1F,0x04,0x04,0x04,0x04,0x04,0x04]), # 5×7
"U": self.Character(width=4, rows=[0x09,0x09,0x09,0x09,0x09,0x09,0x06]),
"V": self.Character(width=5, rows=[0x11,0x11,0x11,0x11,0x11,0x0A,0x04]), # 5×7
"W": self.Character(width=5, rows=[0x11,0x11,0x11,0x15,0x15,0x1B,0x11]), # 5×7
"Y": self.Character(width=4, rows=[0x1F,0x04,0x04,0x04,0x04,0x04,0x04]), # 5*7
"Z": self.Character(width=4, rows=[0x0F,0x08,0x04,0x02,0x01,0x0F,0x00]), # 4×7

":": self.Character(width=2, rows=[0x00,0x03,0x03,0x00,0x03,0x03,0x00]), #2×7
" :": self.Character(width=2, rows=[0x00,0x00,0x00,0x00,0x00,0x00,0x00]), # colon width space
"°C": self.Character(width=4, rows=[0x01,0x0C,0x12,0x02,0x02,0x12,0x0C]), # celcuis 5×7
"°F": self.Character(width=4, rows=[0x01,0x1E,0x02,0x1E,0x02,0x02,0x02]), # farenheit
" ": self.Character(width=4, rows=[0x00,0x00,0x00,0x00,0x00,0x00,0x00]), # space
"Y": self.Character(width=4, rows=[0x1F,0x04,0x04,0x04,0x04,0x04,0x04]), # 5*7

".": self.Character(width=1, rows=[0x00,0x00,0x00,0x00,0x00,0x00,0x01]), # 1×7
"-": self.Character(width=2, rows=[0x00,0x00,0x00,0x03,0x00,0x00,0x00]), # 2×7
"M": self.Character(width=4, rows=[0x00,0x11,0x1B,0x15,0x11,0x11,0x11,0x11]), # 5×7

"/": self.Character(width=2, rows=[0x02,0x02,0x02,0x01,0x01,0x01,0x01,0x01]), # 3×7
"°C2": self.Character(width=4, rows=[0x00,0x01,0x0C,0x12,0x02,0x02,0x12,0x0C]), # 5×7
"°F2": self.Character(width=4, rows=[0x00,0x01,0x1E,0x02,0x1E,0x02,0x02,0x02]),
"V": self.Character(width=5, rows=[0x11,0x11,0x11,0x11,0x11,0x0A,0x04]), # 5×7
"W": self.Character(width=5, rows=[0x11,0x11,0x11,0x15,0x15,0x1B,0x11]), # 5×7

}
self.digital_tube = {
"0": [0x0F, 0x09, 0x09, 0x09, 0x09, 0x09, 0x0F],
Expand All @@ -201,10 +256,10 @@ def initialise_fonts(self):
"3": [0x0F, 0x08, 0x08, 0x0F, 0x08, 0x08, 0x0F],
"4": [0x09, 0x09, 0x09, 0x0F, 0x08, 0x08, 0x08],
"5": [0x0F, 0x01, 0x01, 0x0F, 0x08, 0x08, 0x0F],
"5": [0x0F, 0x01, 0x01, 0x0F, 0x09, 0x09, 0x0F],
"6": [0x0F, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08],
"7": [0x0F, 0x09, 0x09, 0x0F, 0x09, 0x09, 0x0F],
"8": [0x0F, 0x09, 0x09, 0x0F, 0x08, 0x08, 0x0F],
"6": [0x0F, 0x01, 0x01, 0x0F, 0x09, 0x09, 0x0F],
"7": [0x0F, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08],
"8": [0x0F, 0x09, 0x09, 0x0F, 0x09, 0x09, 0x0F],
"9": [0x0F, 0x09, 0x09, 0x0F, 0x08, 0x08, 0x0F],
"A": [0x0F, 0x09, 0x09, 0x0F, 0x09, 0x09, 0x09],
"B": [0x01, 0x01, 0x01, 0x0F, 0x09, 0x09, 0x0F],
"C": [0x0F, 0x01, 0x01, 0x01, 0x01, 0x01, 0x0F],
Expand All @@ -230,3 +285,10 @@ def initialise_fonts(self):
"V": [0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x1F], # 5×7
"W": [0x11, 0x11, 0x11, 0x15, 0x15, 0x1B, 0x11], # 5×7
}







7 changes: 2 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import time
from scheduler import Scheduler
from clock import Clock
from apps import Apps
from pomodoro import Pomodoro
from time_set import TimeSet
import machine
machine.freq(250_000_000)

APP_CLASSES = [
Clock,
Expand All @@ -18,7 +19,3 @@

print("STARTING...")
scheduler.start()

while True:
time.sleep(1)
print(".", end="")
5 changes: 5 additions & 0 deletions scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ def start(self):
def schedule(self, name, duration, callback):
self.schedules.append(self.Schedule(name, duration, callback))

def remove(self, name):
for schedule in self.schedules:
if schedule.name == name:
self.schedules.remove(schedule)

def event_callback(self, t):
for schedule in self.schedules:
if schedule.duration == 1:
Expand Down
7 changes: 7 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from scheduler import Scheduler
scheduler = Scheduler()
from display import Display
dis= Display(scheduler)
scheduler.start()
from rtc import RTC
clock=RTC()