diff options
| author | root <D Delmar Davis feurig@fromhell.com> | 2024-08-29 18:50:17 -0700 |
|---|---|---|
| committer | root <D Delmar Davis feurig@fromhell.com> | 2024-08-29 18:50:17 -0700 |
| commit | 8afd6de99f1a3e3c6faf7371195e382a69559d92 (patch) | |
| tree | 6e625f546d9fbd305a66fff303cd78be220df7af /bin | |
| parent | 4390dfe30633aee6ab3f4ccede0542e71c16e193 (diff) | |
thinkaboutit
Diffstat (limited to 'bin')
| -rw-r--r-- | bin/analogclock.py | 61 |
1 files changed, 45 insertions, 16 deletions
diff --git a/bin/analogclock.py b/bin/analogclock.py index 831b27f..860d6de 100644 --- a/bin/analogclock.py +++ b/bin/analogclock.py @@ -1,10 +1,5 @@ import time -#import subprocess -#from board import SCL, SDA, D4 -#import busio -#import digitalio from PIL import Image, ImageDraw, ImageFont -# import adafruit_ssd1305 from datetime import datetime import math @@ -49,16 +44,50 @@ def draw_clock(t: datetime): draw.line([center,center,center+mx,center+my], fill=255, width=0) draw.line([center,center,center+hx,center+hy], fill=255, width=0) -onlyonce = True -while onlyonce: - thetime=datetime.now() - # Draw a black filled box to clear the image. - draw.rectangle((0, 0, width, height), outline=0, fill=0) - draw_clock(thetime) - # Display image. - #disp.image(image) - image.show() - time.sleep(0.1) - onlyonce = False +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT +import digitalio +import board +from adafruit_rgb_display.rgb import color565 +from adafruit_rgb_display import st7789 + +# Configuration for CS and DC pins for Raspberry Pi +cs_pin = digitalio.DigitalInOut(board.CE0) +dc_pin = digitalio.DigitalInOut(board.D25) +reset_pin = None +BAUDRATE = 64000000 # The pi can be very fast! +# Create the ST7789 display: +display = st7789.ST7789( + board.SPI(), + cs=cs_pin, + dc=dc_pin, + rst=reset_pin, + baudrate=BAUDRATE, + width=135, + height=240, + x_offset=53, + y_offset=40, +) + +backlight = digitalio.DigitalInOut(board.D22) +backlight.switch_to_output() +backlight.value = True +buttonA = digitalio.DigitalInOut(board.D23) +buttonB = digitalio.DigitalInOut(board.D24) +buttonA.switch_to_input() +buttonB.switch_to_input() + +# Main loop: +while True: + if buttonA.value and buttonB.value: + backlight.value = False # turn off backlight + else: + backlight.value = True # turn on backlight + if buttonB.value and not buttonA.value: # just button A pressed + display.fill(color565(255, 0, 0)) # red + if buttonA.value and not buttonB.value: # just button B pressed + display.fill(color565(0, 0, 255)) # blue + if not buttonA.value and not buttonB.value: # none pressed + display.fill(color565(0, 255, 0)) # green |
