github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/examples/hid-mouse/main.go (about) 1 package main 2 3 import ( 4 "machine" 5 "machine/usb/hid/mouse" 6 "time" 7 ) 8 9 func main() { 10 button := machine.BUTTON 11 button.Configure(machine.PinConfig{Mode: machine.PinInputPullup}) 12 13 mouse := mouse.Port() 14 15 for { 16 if !button.Get() { 17 for j := 0; j < 5; j++ { 18 for i := 0; i < 100; i++ { 19 mouse.Move(1, 0) 20 time.Sleep(1 * time.Millisecond) 21 } 22 23 for i := 0; i < 100; i++ { 24 mouse.Move(0, 1) 25 time.Sleep(1 * time.Millisecond) 26 } 27 28 for i := 0; i < 100; i++ { 29 mouse.Move(-1, -1) 30 time.Sleep(1 * time.Millisecond) 31 } 32 } 33 34 time.Sleep(100 * time.Millisecond) 35 } 36 } 37 }