tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/shifter/pybadge.go (about)

     1  //go:build pybadge
     2  
     3  package shifter
     4  
     5  import "machine"
     6  
     7  const (
     8  	BUTTON_LEFT   = 0
     9  	BUTTON_UP     = 1
    10  	BUTTON_DOWN   = 2
    11  	BUTTON_RIGHT  = 3
    12  	BUTTON_SELECT = 4
    13  	BUTTON_START  = 5
    14  	BUTTON_A      = 6
    15  	BUTTON_B      = 7
    16  )
    17  
    18  // NewButtons returns a new shifter device for the buttons on an AdaFruit PyBadge
    19  func NewButtons() Device {
    20  	return Device{
    21  		latch: machine.BUTTON_LATCH,
    22  		clk:   machine.BUTTON_CLK,
    23  		out:   machine.BUTTON_OUT,
    24  		Pins:  make([]ShiftPin, int(EIGHT_BITS)),
    25  		bits:  EIGHT_BITS,
    26  	}
    27  }
    28  
    29  // ReadInput returns the latest input readings from the PyBadge.
    30  func (d *Device) ReadInput() (uint8, error) {
    31  	return d.Read8Input()
    32  }