shifter: simplify API surface for PyBadge (#137)

* shifter: simplify API surface and use build directive to directly match the PyBadge

Signed-off-by: Ron Evans <ron@hybridgroup.com>

* shifter: further simplify API for PyBadge

Signed-off-by: Ron Evans <ron@hybridgroup.com>
This commit is contained in:
Ron Evans
2020-03-06 06:29:30 +00:00
committed by GitHub
parent 583e80026a
commit 41c6e3be0b
3 changed files with 44 additions and 23 deletions
+11 -22
View File
@@ -1,53 +1,42 @@
// This example is designed to implement the button shifter for a PyBadge.
package main
import (
"machine"
"time"
"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 := shifter.NewButtons()
buttons.Configure()
for {
// Update the pins state, to later be returned by .Get()
buttons.Read8Input()
buttons.ReadInput()
if buttons.Pins[BUTTON_LEFT].Get() {
if buttons.Pins[shifter.BUTTON_LEFT].Get() {
println("Button LEFT pressed")
}
if buttons.Pins[BUTTON_UP].Get() {
if buttons.Pins[shifter.BUTTON_UP].Get() {
println("Button UP pressed")
}
if buttons.Pins[BUTTON_DOWN].Get() {
if buttons.Pins[shifter.BUTTON_DOWN].Get() {
println("Button DOWN pressed")
}
if buttons.Pins[BUTTON_RIGHT].Get() {
if buttons.Pins[shifter.BUTTON_RIGHT].Get() {
println("Button RIGHT pressed")
}
if buttons.Pins[BUTTON_SELECT].Get() {
if buttons.Pins[shifter.BUTTON_SELECT].Get() {
println("Button SELECT pressed")
}
if buttons.Pins[BUTTON_START].Get() {
if buttons.Pins[shifter.BUTTON_START].Get() {
println("Button START pressed")
}
if buttons.Pins[BUTTON_A].Get() {
if buttons.Pins[shifter.BUTTON_A].Get() {
println("Button A pressed")
}
if buttons.Pins[BUTTON_B].Get() {
if buttons.Pins[shifter.BUTTON_B].Get() {
println("Button B pressed")
}
time.Sleep(100 * time.Millisecond)