|
| 1 | +// This example is designed to implement the button shifter for a PyBadge. |
1 | 2 | package main |
2 | 3 |
|
3 | 4 | import ( |
4 | | - "machine" |
5 | 5 | "time" |
6 | 6 |
|
7 | 7 | "tinygo.org/x/drivers/shifter" |
8 | 8 | ) |
9 | 9 |
|
10 | | -const ( |
11 | | - BUTTON_LEFT = iota |
12 | | - BUTTON_UP |
13 | | - BUTTON_DOWN |
14 | | - BUTTON_RIGHT |
15 | | - BUTTON_SELECT |
16 | | - BUTTON_START |
17 | | - BUTTON_A |
18 | | - BUTTON_B |
19 | | -) |
20 | | - |
21 | 10 | func main() { |
22 | | - buttons := shifter.New(shifter.EIGHT_BITS, machine.BUTTON_LATCH, machine.BUTTON_CLK, machine.BUTTON_OUT) |
| 11 | + buttons := shifter.NewButtons() |
23 | 12 | buttons.Configure() |
24 | 13 |
|
25 | 14 | for { |
26 | 15 | // Update the pins state, to later be returned by .Get() |
27 | | - buttons.Read8Input() |
| 16 | + buttons.ReadInput() |
28 | 17 |
|
29 | | - if buttons.Pins[BUTTON_LEFT].Get() { |
| 18 | + if buttons.Pins[shifter.BUTTON_LEFT].Get() { |
30 | 19 | println("Button LEFT pressed") |
31 | 20 | } |
32 | | - if buttons.Pins[BUTTON_UP].Get() { |
| 21 | + if buttons.Pins[shifter.BUTTON_UP].Get() { |
33 | 22 | println("Button UP pressed") |
34 | 23 | } |
35 | | - if buttons.Pins[BUTTON_DOWN].Get() { |
| 24 | + if buttons.Pins[shifter.BUTTON_DOWN].Get() { |
36 | 25 | println("Button DOWN pressed") |
37 | 26 | } |
38 | | - if buttons.Pins[BUTTON_RIGHT].Get() { |
| 27 | + if buttons.Pins[shifter.BUTTON_RIGHT].Get() { |
39 | 28 | println("Button RIGHT pressed") |
40 | 29 | } |
41 | | - if buttons.Pins[BUTTON_SELECT].Get() { |
| 30 | + if buttons.Pins[shifter.BUTTON_SELECT].Get() { |
42 | 31 | println("Button SELECT pressed") |
43 | 32 | } |
44 | | - if buttons.Pins[BUTTON_START].Get() { |
| 33 | + if buttons.Pins[shifter.BUTTON_START].Get() { |
45 | 34 | println("Button START pressed") |
46 | 35 | } |
47 | | - if buttons.Pins[BUTTON_A].Get() { |
| 36 | + if buttons.Pins[shifter.BUTTON_A].Get() { |
48 | 37 | println("Button A pressed") |
49 | 38 | } |
50 | | - if buttons.Pins[BUTTON_B].Get() { |
| 39 | + if buttons.Pins[shifter.BUTTON_B].Get() { |
51 | 40 | println("Button B pressed") |
52 | 41 | } |
53 | 42 | time.Sleep(100 * time.Millisecond) |
|
0 commit comments