tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/l9110x/speed/main.go (about) 1 package main 2 3 import ( 4 "machine" 5 "time" 6 7 "tinygo.org/x/drivers/l9110x" 8 ) 9 10 const ( 11 maxSpeed = 100 12 ) 13 14 func main() { 15 machine.D11.Configure(machine.PinConfig{Mode: machine.PinOutput}) 16 machine.D12.Configure(machine.PinConfig{Mode: machine.PinOutput}) 17 18 err := machine.TCC0.Configure(machine.PWMConfig{}) 19 if err != nil { 20 println(err.Error()) 21 return 22 } 23 24 ca, err := machine.TCC0.Channel(machine.D11) 25 if err != nil { 26 println(err.Error()) 27 return 28 } 29 30 cb, err := machine.TCC0.Channel(machine.D12) 31 if err != nil { 32 println(err.Error()) 33 return 34 } 35 36 wheel := l9110x.NewWithSpeed(ca, cb, machine.TCC0) 37 wheel.Configure() 38 39 for i := 0; i <= 10; i++ { 40 println("Forward") 41 var i uint32 42 for i = 0; i < maxSpeed; i += 10 { 43 wheel.Forward(i) 44 time.Sleep(time.Millisecond * 100) 45 } 46 47 println("Stop") 48 wheel.Stop() 49 time.Sleep(time.Millisecond * 1000) 50 51 println("Backward") 52 for i = 0; i < maxSpeed; i += 10 { 53 wheel.Backward(i) 54 time.Sleep(time.Millisecond * 100) 55 } 56 57 println("Stop") 58 wheel.Stop() 59 time.Sleep(time.Millisecond * 1000) 60 } 61 62 println("Stop") 63 wheel.Stop() 64 }