mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 03:53:42 +00:00
Add USB HID joystick support (#3366)
machine/usb: add USB HID joystick support
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
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++
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user