tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/ttp229/main.go (about)

     1  package main
     2  
     3  import (
     4  	"time"
     5  
     6  	"tinygo.org/x/drivers/ttp229"
     7  
     8  	"machine"
     9  )
    10  
    11  func main() {
    12  	time.Sleep(5 * time.Second)
    13  	sensor := ttp229.NewPin(machine.A5, machine.A4)
    14  	sensor.Configure(ttp229.Configuration{Inputs: 16})
    15  
    16  	println("READY")
    17  	for {
    18  		sensor.ReadKeys()
    19  		for i := byte(0); i < 16; i++ {
    20  			if sensor.IsKeyPressed(i) {
    21  				print("1 ")
    22  			} else {
    23  				print("0 ")
    24  			}
    25  		}
    26  		println("")
    27  
    28  		println("Pressed key:", sensor.GetKey())
    29  
    30  		for i := byte(0); i < 16; i++ {
    31  			if sensor.IsKeyDown(i) {
    32  				println("Key", i, "is down")
    33  			} else if sensor.IsKeyUp(i) {
    34  				println("Key", i, "is up")
    35  			}
    36  		}
    37  
    38  		time.Sleep(100 * time.Millisecond)
    39  	}
    40  }