mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-09 17:33:43 +00:00
added generic 8bit shift register (#107)
* shifter: added generic 8bit shift register driver with ShiftPin Pin-compatible GPIO interface
This commit is contained in:
committed by
Ron Evans
parent
18f0722728
commit
adb0c2c261
@@ -0,0 +1,50 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/shifter"
|
||||
)
|
||||
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
||||
// Faster
|
||||
pressed, _ := buttons.Read8Input()
|
||||
if pressed&machine.BUTTON_LEFT_MASK > 0 {
|
||||
println("Button LEFT pressed")
|
||||
}
|
||||
if pressed&machine.BUTTON_UP_MASK > 0 {
|
||||
println("Button UP pressed")
|
||||
}
|
||||
if pressed&machine.BUTTON_DOWN_MASK > 0 {
|
||||
println("Button DOWN pressed")
|
||||
}
|
||||
if pressed&machine.BUTTON_RIGHT_MASK > 0 {
|
||||
println("Button RIGHT pressed")
|
||||
}
|
||||
if pressed&machine.BUTTON_SELECT_MASK > 0 {
|
||||
println("Button SELECT pressed")
|
||||
}
|
||||
if pressed&machine.BUTTON_START_MASK > 0 {
|
||||
println("Button START pressed")
|
||||
}
|
||||
if pressed&machine.BUTTON_A_MASK > 0 {
|
||||
println("Button A pressed")
|
||||
}
|
||||
if pressed&machine.BUTTON_B_MASK > 0 {
|
||||
println("Button B pressed")
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user