mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-07-26 10:38:41 +00:00
857ab80ae6
Adds the necessary function addresses for reading and writing encoders on a seesaw. Also provides two helper functions to make this easier.
36 lines
686 B
Go
36 lines
686 B
Go
package main
|
|
|
|
import (
|
|
"machine"
|
|
"time"
|
|
|
|
"tinygo.org/x/drivers/seesaw"
|
|
)
|
|
|
|
// example reading the position of a rotary encoder (4991) powered by a seesaw
|
|
// https://learn.adafruit.com/adafruit-i2c-qt-rotary-encoder/arduino
|
|
func main() {
|
|
// This assumes you are using an Adafruit QT Py RP2040 for its Stemma QT connector
|
|
// https://www.adafruit.com/product/4900
|
|
i2c := machine.I2C1
|
|
i2c.Configure(machine.I2CConfig{
|
|
SCL: machine.I2C1_QT_SCL_PIN,
|
|
SDA: machine.I2C1_QT_SDA_PIN,
|
|
})
|
|
|
|
dev := seesaw.New(i2c)
|
|
dev.Address = 0x36
|
|
|
|
for {
|
|
time.Sleep(time.Second)
|
|
|
|
pos, err := dev.GetEncoderPosition(0, false)
|
|
if err != nil {
|
|
println(err)
|
|
continue
|
|
}
|
|
|
|
println(pos)
|
|
}
|
|
}
|