From 4943ea9c15004707f3438f665f0e4b7681b9bbd0 Mon Sep 17 00:00:00 2001
From: Tom Charnock <tom@charnock.fr>
Date: Fri, 3 Jan 2025 20:43:16 +0100
Subject: [PATCH] Adding auto timeout for screen

---
 code.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/code.py b/code.py
index e74bace..96adc4a 100644
--- a/code.py
+++ b/code.py
@@ -361,11 +361,23 @@ def main(rate=0.05, start=3):
     mode = 0
     language = 0
     backlight = True
+    counter = 0
     while True:
         _p, _m = poll()
         t = release_countdown(_p, t, start=start)
         tm = get_time(_m, tm)
 
+        if any(_p) or any(_m):
+            counter = 0
+        else:
+            if counter < 100:
+                counter += 1
+
+        if counter == 100:
+            tft_bl.value = False
+        elif counter == 0:
+            tft_bl.value = backlight
+
         if all([_tm > 60 for _tm in tm]):
             if not settings:
                 settings = True