hybridgroup.gobot/examples/chip_drv2605l.go

44 lines
728 B
Go

//go:build example
// +build example
//
// Do not build by default.
package main
import (
"fmt"
"time"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/drivers/i2c"
"gobot.io/x/gobot/v2/platforms/chip"
)
func main() {
board := chip.NewAdaptor()
haptic := i2c.NewDRV2605LDriver(board)
work := func() {
gobot.Every(3*time.Second, func() {
pause := haptic.GetPauseWaveform(50)
if err := haptic.SetSequence([]byte{1, pause, 1, pause, 1}); err != nil {
fmt.Println(err)
}
if err := haptic.Go(); err != nil {
fmt.Println(err)
}
})
}
robot := gobot.NewRobot("DRV2605LBot",
[]gobot.Connection{board},
[]gobot.Device{haptic},
work,
)
if err := robot.Start(); err != nil {
panic(err)
}
}