mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 20:13:40 +00:00
a7ff2731b9
machine/usb: add USB HID joystick support
28 lines
440 B
Go
28 lines
440 B
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"machine/usb/joystick"
|
|
"math"
|
|
"time"
|
|
)
|
|
|
|
var js = joystick.Port()
|
|
|
|
func main() {
|
|
log.SetFlags(log.Lmicroseconds)
|
|
ticker := time.NewTicker(10 * time.Millisecond)
|
|
cnt := 0
|
|
const f = 3.0
|
|
for range ticker.C {
|
|
t := float64(cnt) * 0.01
|
|
x := 32767 * math.Sin(2*math.Pi*f*t)
|
|
button := cnt%100 > 50
|
|
js.SetButton(2, button)
|
|
js.SetButton(3, !button)
|
|
js.SetAxis(0, int(x))
|
|
js.SendState()
|
|
cnt++
|
|
}
|
|
}
|