继电器文档、gpio demo 上传

This commit is contained in:
2024-12-12 10:33:33 +08:00
parent df9dbb0926
commit 3f760e2955
2 changed files with 48 additions and 0 deletions

48
demo/gpio2/main.go Normal file
View File

@@ -0,0 +1,48 @@
package main
import (
"fmt"
"game-driver/internal/routes/play/card_pusher"
"game-driver/logger"
"github.com/warthog618/go-gpiocdev/device/rpi"
"time"
)
func main() {
logger.DefaultLogger()
defer logger.Sync()
device, err := card_pusher.New(&card_pusher.LineGroup{
Name: "gpiochip0",
OutOK: rpi.GPIO6,
Lower: rpi.GPIO13,
Error: rpi.GPIO19,
Empty: rpi.GPIO26,
Push: rpi.GPIO11,
Reset: rpi.GPIO22,
Pull: rpi.GPIO27,
})
if err != nil {
fmt.Println("打开 GPIO 设备失败:", err)
return
}
defer device.Close()
for {
var userInput string
fmt.Println("按 o/p/r 发送信号")
_, _ = fmt.Scanln(&userInput)
if userInput == "o" {
device.PushCard()
}
if userInput == "p" {
device.PullCard()
}
if userInput == "r" {
device.Reset()
}
time.Sleep(1 * time.Second)
}
}