RaspberryPI button press
Jump to navigation
Jump to search
Mygtukas reaguoja į paspaudimą ir parašo ekrane tekstą.
Sujungimas
Mygtuko prijungimas prie pin 6 ir pin 12
Golang Kodas
package main
import (
. "github.com/cyoung/rpi"
"fmt"
"time"
)
func main() {
WiringPiSetup()
pin := 12
go func() {
last_time := time.Now().UnixNano() / 1000000
btn_pushed := 0
for pinas := range WiringPiISR(BoardToPin(pin), INT_EDGE_FALLING) {
if pinas > -1 {
n := time.Now().UnixNano() / 1000000
delta := n - last_time
if delta > 800 { //software debouncing
fmt.Println("button pressed")
last_time = n
btn_pushed++
}
}
}
}()
for {
// empty cycle
}
}