tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/servo/servo.go (about) 1 package main 2 3 import ( 4 "machine" 5 "time" 6 7 "tinygo.org/x/drivers/servo" 8 ) 9 10 // Configuration for the Arduino Uno. 11 // Please change the PWM and pin if you want to try this example on a different 12 // board. 13 var ( 14 pwm = machine.Timer1 15 pin = machine.D9 16 ) 17 18 func main() { 19 s, err := servo.New(pwm, pin) 20 if err != nil { 21 for { 22 println("could not configure servo") 23 time.Sleep(time.Second) 24 } 25 return 26 } 27 28 println("setting to 0°") 29 s.SetMicroseconds(1000) 30 time.Sleep(3 * time.Second) 31 32 println("setting to 45°") 33 s.SetMicroseconds(1500) 34 time.Sleep(3 * time.Second) 35 36 println("setting to 90°") 37 s.SetMicroseconds(2000) 38 time.Sleep(3 * time.Second) 39 40 for { 41 time.Sleep(time.Second) 42 } 43 }