mess around with m5stickc

This commit is contained in:
Joel Wetzell
2026-04-09 23:14:30 -05:00
commit 6c68465d9c
3 changed files with 98 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
module m5stickc
go 1.25.8
require tinygo.org/x/drivers v0.34.0
require github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
+4
View File
@@ -0,0 +1,4 @@
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.34.0 h1:lw8ePJeUSn9oICKBvQXHC9TIE+J00OfXfkGTrpXM9Iw=
tinygo.org/x/drivers v0.34.0/go.mod h1:ZdErNrApSABdVXjA1RejD67R8SNRI6RKVfYgQDZtKtk=
+87
View File
@@ -0,0 +1,87 @@
package main
import (
"image/color"
"machine"
"time"
"tinygo.org/x/drivers/axp192"
"tinygo.org/x/drivers/st7735"
)
func main() {
i2c := machine.I2C0
i2c.Configure(machine.I2CConfig{
Frequency: 100e3,
SCL: machine.GPIO22,
SDA: machine.GPIO21,
})
axp := axp192.New(i2c)
axp.SetLDOEnable(2, true)
machine.SPI2.Configure(machine.SPIConfig{
Frequency: 27000000,
SCK: machine.GPIO13,
SDO: machine.GPIO15,
})
time.Sleep(time.Second)
display := st7735.New(
machine.SPI2,
machine.GPIO18,
machine.GPIO23,
machine.GPIO5,
machine.NoPin,
)
display.Configure(st7735.Config{
Model: st7735.MINI80x160,
Width: 80,
Height: 160,
// ColumnOffset: 26,
// RowOffset: 1,
Rotation: st7735.ROTATION_270,
})
red := color.RGBA{255, 0, 0, 255}
blue := color.RGBA{0, 0, 255, 255}
black := color.RGBA{0, 0, 0, 255}
display.FillScreen(black)
time.Sleep(500 * time.Millisecond)
display.FillScreen(red)
time.Sleep(500 * time.Millisecond)
display.FillScreen(black)
led := machine.GPIO10
led.Configure(machine.PinConfig{Mode: machine.PinOutput})
led.Set(true)
buttonA := machine.GPIO37
buttonA.Configure(machine.PinConfig{Mode: machine.PinInput})
buttonB := machine.GPIO39
buttonB.Configure(machine.PinConfig{Mode: machine.PinInput})
for {
// display.FillScreen(red)
// time.Sleep(500 * time.Millisecond)
// display.FillScreen(black)
// time.Sleep(500 * time.Millisecond)
valueA := buttonA.Get()
valueB := buttonB.Get()
if !valueA {
display.FillRectangle(0, 0, 80, 80, red)
} else {
display.FillRectangle(0, 0, 80, 80, black)
}
if !valueB {
display.FillRectangle(80, 0, 80, 80, blue)
} else {
display.FillRectangle(80, 0, 80, 80, black)
}
}
}