Initial project working with a clock
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
2026-09-07 17:28:34 -04:00
parent 07e8f8ff45
commit b9195b33bc
3 changed files with 66 additions and 2 deletions
+7
View File
@@ -1,3 +1,10 @@
module git.metaunix.net/bitgoblin/pico-time module git.metaunix.net/bitgoblin/pico-time
go 1.25.2 go 1.25.2
require (
tinygo.org/x/drivers v0.36.0
tinygo.org/x/tinyfont v0.7.0
)
require github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
+6
View File
@@ -0,0 +1,6 @@
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
tinygo.org/x/drivers v0.36.0 h1:F0x342A6GWqh6abtCa57uAxCyz/b9MbGzvIVvIf+gpE=
tinygo.org/x/drivers v0.36.0/go.mod h1:DQgKyHkB4G6IEOKVTAjApbKnWGwESN91EVJO+nMOE9Y=
tinygo.org/x/tinyfont v0.7.0 h1:Ju901eGRThlHLoti9K7myMYyv4phd3I0DrJwc14NTTU=
tinygo.org/x/tinyfont v0.7.0/go.mod h1:onflMSkpWl7r7j4MIqhPEVV39pn7yL4N3MOePl3G+G8=
+52 -1
View File
@@ -2,8 +2,59 @@ package main
import ( import (
"fmt" "fmt"
"image/color"
"machine"
"time"
"tinygo.org/x/drivers/ssd1306"
"tinygo.org/x/tinyfont"
"tinygo.org/x/tinyfont/proggy"
"tinygo.org/x/tinyfont/freemono"
)
var (
white = color.RGBA{R: 255, G: 255, B: 255, A: 255}
black = color.RGBA{R: 0, G: 0, B: 0, A: 255}
) )
func main() { func main() {
fmt.Println("Hello there.") // Configure I2C0 using GP4 (SDA) and GP5 (SCL) at 400kHz
machine.I2C0.Configure(machine.I2CConfig{
Frequency: 400 * machine.KHz,
SDA: machine.GP16,
SCL: machine.GP17,
})
// Initialize the display (default I2C address for SSD1306 is usually 0x3C)
display := ssd1306.NewI2C(machine.I2C0)
display.Configure(ssd1306.Config{
Address: 0x3C,
Width: 128,
Height: 64,
})
display.ClearDisplay()
// Base time for clock tracking (update to current time or set via NTP)
currentTime := time.Date(2026, time.September, 7, 12, 0, 0, 0, time.UTC)
ticker := time.NewTicker(1 * time.Second)
for range ticker.C {
currentTime = currentTime.Add(1 * time.Second)
// Format time and date strings
timeStr := fmt.Sprintf("%02d:%02d:%02d", currentTime.Hour(), currentTime.Minute(), currentTime.Second())
dateStr := currentTime.Format("Mon, Jan 02 2006")
// Clear screen buffer
display.ClearBuffer()
// Render text to display buffer:
// WriteLine(target, font, x, y, text, color)
tinyfont.WriteLine(display, &proggy.TinySZ8pt7b, 16, 14, dateStr, white)
tinyfont.WriteLine(display, &freemono.Bold12pt7b, 6, 44, timeStr, white)
// Push frame buffer to the OLED panel
display.Display()
}
} }