Open olablt opened 4 years ago
Well...this might work, except that machine.PinInputPullup
has not been implemented on Bluepill yet (I only tested it on a BBC micro:bit). You would have to use external pull-ups.
package main
import (
"machine"
"time"
)
func main() {
clk := machine.PB9
dta := machine.PB8
sw := machine.PB7
clk.Configure(machine.PinConfig{Mode: machine.PinInputPullup})
dta.Configure(machine.PinConfig{Mode: machine.PinInputPullup})
sw.Configure(machine.PinConfig{Mode: machine.PinInputPullup})
var clkNow, clkPrv bool
for {
if !sw.Get() {
println("Switch pressed")
time.Sleep(time.Millisecond * 250)
}
clkNow = clk.Get()
if clkNow != clkPrv && clkNow {
if dta.Get() != clkNow {
println("Turing clockwise")
} else {
println("Turing anti-clockwise")
}
}
clkPrv = clkNow
time.Sleep(time.Millisecond * 1)
}
}
This code worked for me on RPi Pico (with minor changes in pin names). Clockwise and anti-clockwise were reversed in my case, but that's easy to change.
tinygo version 0.27.0 linux/amd64
Thanks, @alankrantas !
I have Blue Pill board and Rotary Encoder connected. I can not find any info on how to implement interrupts on GPIO input pins.
Are there any attempts to make a driver for encoder?
Arduino library code: https://github.com/PaulStoffregen/Encoder/blob/master/Encoder.h