问题描述
我正在尝试使用 Arduino ATMega2560 和 Go 编写的代码来转动电机。 这里有一个使用 TinyGo v0.14.1 的示例: https://create.arduino.cc/projecthub/alankrantas/tinygo-on-arduino-uno-an-introduction-6130f6
这个例子本质上是这样的:
func main() {
machine.InitPWM()
led := machine.PWM{machine.D9}
led.Configure()
value := 0
led.Set(uint16(value))
}
当我尝试调用 machine.InitPWM()
时出现错误 InitPWM not declared by package machine
TinyGo 的当前版本(以及我正在运行的版本)是 v0.19。似乎机器包已被修改为以不同方式使用 PWM,但是,我找不到任何地方如何正确使用它。
解决方法
ATMega2560 的 InitPWM
包中确实没有 machine
函数 - https://tinygo.org/docs/reference/microcontrollers/machine/arduino-mega2560/
以下是一些 PWM 示例:https://github.com/tinygo-org/tinygo/tree/release/src/examples/pwm