85 lines
1.7 KiB
Go
85 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"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 {
|
|
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)
|
|
}
|
|
fmt.Printf("Button A: %v, Button B: %v\n", valueA, valueB)
|
|
}
|
|
}
|