mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-09 17:33:43 +00:00
new API for shifter driver.
this doesn't break existing code, but it might no longer work as expected
This commit is contained in:
committed by
Ron Evans
parent
c7cbd7c6cd
commit
583e80026a
+21
-16
@@ -7,42 +7,47 @@ import (
|
||||
"tinygo.org/x/drivers/shifter"
|
||||
)
|
||||
|
||||
const (
|
||||
BUTTON_LEFT = iota
|
||||
BUTTON_UP
|
||||
BUTTON_DOWN
|
||||
BUTTON_RIGHT
|
||||
BUTTON_SELECT
|
||||
BUTTON_START
|
||||
BUTTON_A
|
||||
BUTTON_B
|
||||
)
|
||||
|
||||
func main() {
|
||||
buttons := shifter.New(shifter.EIGHT_BITS, machine.BUTTON_LATCH, machine.BUTTON_CLK, machine.BUTTON_OUT)
|
||||
buttons.Configure()
|
||||
|
||||
for {
|
||||
// Slower
|
||||
for i := 0; i < 8; i++ {
|
||||
if buttons.Pins[i].Get() {
|
||||
println("Button", i, "pressed")
|
||||
}
|
||||
}
|
||||
// Update the pins state, to later be returned by .Get()
|
||||
buttons.Read8Input()
|
||||
|
||||
// Faster
|
||||
pressed, _ := buttons.Read8Input()
|
||||
if pressed&machine.BUTTON_LEFT_MASK > 0 {
|
||||
if buttons.Pins[BUTTON_LEFT].Get() {
|
||||
println("Button LEFT pressed")
|
||||
}
|
||||
if pressed&machine.BUTTON_UP_MASK > 0 {
|
||||
if buttons.Pins[BUTTON_UP].Get() {
|
||||
println("Button UP pressed")
|
||||
}
|
||||
if pressed&machine.BUTTON_DOWN_MASK > 0 {
|
||||
if buttons.Pins[BUTTON_DOWN].Get() {
|
||||
println("Button DOWN pressed")
|
||||
}
|
||||
if pressed&machine.BUTTON_RIGHT_MASK > 0 {
|
||||
if buttons.Pins[BUTTON_RIGHT].Get() {
|
||||
println("Button RIGHT pressed")
|
||||
}
|
||||
if pressed&machine.BUTTON_SELECT_MASK > 0 {
|
||||
if buttons.Pins[BUTTON_SELECT].Get() {
|
||||
println("Button SELECT pressed")
|
||||
}
|
||||
if pressed&machine.BUTTON_START_MASK > 0 {
|
||||
if buttons.Pins[BUTTON_START].Get() {
|
||||
println("Button START pressed")
|
||||
}
|
||||
if pressed&machine.BUTTON_A_MASK > 0 {
|
||||
if buttons.Pins[BUTTON_A].Get() {
|
||||
println("Button A pressed")
|
||||
}
|
||||
if pressed&machine.BUTTON_B_MASK > 0 {
|
||||
if buttons.Pins[BUTTON_B].Get() {
|
||||
println("Button B pressed")
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
Reference in New Issue
Block a user