From 405dc9c7ddfa98e672190d407e54a3a75cb9c46b Mon Sep 17 00:00:00 2001 From: "Christopher P. Yarger" Date: Mon, 11 Oct 2021 09:50:12 -0400 Subject: [PATCH 1/4] Add Letters T K J Z G I R Q --- display.py | 30 +++++++++++++++++++++++++----- test.py | 7 +++++++ 2 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 test.py diff --git a/display.py b/display.py index 15077da..b89b467 100644 --- a/display.py +++ b/display.py @@ -173,26 +173,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], @@ -230,3 +243,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 } + + + + + + + diff --git a/test.py b/test.py new file mode 100644 index 0000000..65652c3 --- /dev/null +++ b/test.py @@ -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() \ No newline at end of file From a1837893c1e66b77cf5169d9119d6588503f9cfa Mon Sep 17 00:00:00 2001 From: Jc Coquery <32167067+jcoquerygithub@users.noreply.github.com> Date: Fri, 3 Jun 2022 17:16:32 +0200 Subject: [PATCH 2/4] Implementing backlight management thought third button in Clock app. Improving screen flickering as well. Code cleanup --- clock.py | 7 +++++++ display.py | 32 ++++++++++++++++++++++++-------- main.py | 7 ++----- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/clock.py b/clock.py index 3d80ba7..d9c5a82 100644 --- a/clock.py +++ b/clock.py @@ -2,6 +2,7 @@ from apps import App from display import Display from rtc import RTC +from buttons import Buttons class Clock(App): @@ -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 @@ -37,3 +40,7 @@ def update_time(self): now = "%02d:%02d" % (t[3], t[4]) self.display.show_day(t[6]) self.display.show_text(now) + + def backlight_callback(self, t): + self.display.switch_backlight() + diff --git a/display.py b/display.py index 15077da..e4eafc5 100644 --- a/display.py +++ b/display.py @@ -1,7 +1,7 @@ -from machine import Pin, Timer +from machine import Pin from util import singleton - +from utime import sleep_us @singleton class Display: @@ -10,6 +10,8 @@ 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) @@ -21,6 +23,11 @@ def __init__(self, scheduler): self.disp_offset = 2 self.initialise_fonts() self.initialise_icons() + + # CPU freq needs to be increase to 250 for better results + self.backlight_sleep = [10, 100, 500, 1000, 1500] # From 10 (low) to 1500(High) + self.current_backlight = 4 + scheduler.schedule("enable-leds", 1, self.enable_leds) def enable_leds(self, t): @@ -39,6 +46,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): @@ -80,14 +90,20 @@ 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.current_backlight == 4: + self.current_backlight = 0 + else: + self.current_backlight += 1 + def print(self): for row in range(0, 8): for pos in range(0, 24): @@ -201,10 +217,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], diff --git a/main.py b/main.py index 454b611..9fbc281 100644 --- a/main.py +++ b/main.py @@ -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, @@ -18,7 +19,3 @@ print("STARTING...") scheduler.start() - -while True: - time.sleep(1) - print(".", end="") From 3679fa862217eb660f6413163b76bcae0b9348e9 Mon Sep 17 00:00:00 2001 From: Jc Coquery <32167067+jcoquerygithub@users.noreply.github.com> Date: Sat, 11 Jun 2022 12:04:16 +0200 Subject: [PATCH 3/4] Implementing auto backlight function, reducing to 4 level of backlight. 3rd button cycle through 3 different backlight and auto backlight. --- clock.py | 2 ++ display.py | 40 +++++++++++++++++++++++++++++++++------- scheduler.py | 5 +++++ 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/clock.py b/clock.py index d9c5a82..a32a494 100644 --- a/clock.py +++ b/clock.py @@ -40,6 +40,8 @@ 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() diff --git a/display.py b/display.py index e4eafc5..7f3583f 100644 --- a/display.py +++ b/display.py @@ -1,4 +1,4 @@ -from machine import Pin +from machine import Pin, ADC from util import singleton from utime import sleep_us @@ -15,6 +15,8 @@ def __init__(self, scheduler): 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 @@ -23,12 +25,17 @@ def __init__(self, scheduler): self.disp_offset = 2 self.initialise_fonts() self.initialise_icons() - - # CPU freq needs to be increase to 250 for better results - self.backlight_sleep = [10, 100, 500, 1000, 1500] # From 10 (low) to 1500(High) - self.current_backlight = 4 - 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, 500, 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 @@ -99,11 +106,30 @@ def sidelight_off(self): self.leds[0][5] = 0 def switch_backlight(self): - if self.current_backlight == 4: + 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 > 10000: + self.current_backlight = 2 + else: + self.current_backlight = 3 + def print(self): for row in range(0, 8): for pos in range(0, 24): diff --git a/scheduler.py b/scheduler.py index 6384b6a..02a0f4f 100644 --- a/scheduler.py +++ b/scheduler.py @@ -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: From 02ad9b3d9924f80201b33c46e50f54eb6ed69771 Mon Sep 17 00:00:00 2001 From: Jc Coquery <32167067+jcoquerygithub@users.noreply.github.com> Date: Tue, 21 Jun 2022 18:49:29 +0200 Subject: [PATCH 4/4] Ajusting backlight values for better autoLight detection --- display.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/display.py b/display.py index 7f3583f..bf3f6e9 100644 --- a/display.py +++ b/display.py @@ -29,7 +29,7 @@ def __init__(self, scheduler): self.scheduler = scheduler # CPU freq needs to be increase to 250 for better results - self.backlight_sleep = [10, 100, 500, 1500] # From 10 (low) to 1500(High) + 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") @@ -125,7 +125,7 @@ def update_auto_backlight_value(self, t): self.current_backlight = 0 elif aim > 58000: self.current_backlight = 1 - elif aim > 10000: + elif aim > 40000: self.current_backlight = 2 else: self.current_backlight = 3