7
在 Windows 环境下使用 VSCode 和 Go 语言开发 Arduino
source link: https://discretetom.github.io/posts/windows-vscode-tinygo-arduino/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
以下代码使用 Windows Powershell 执行
安装 Scoop
# PowerShell must be allowed to execute local scripts for your user account
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
# install scoop from a script
iwr -useb get.scoop.sh | iex
安装 golang
scoop install go
安装 TinyGo
scoop install tinygo
安装 AVR 相关工具
因为 Arduino Nano 的处理器是 AVR 架构,所以需要安装 AVR 相关工具
scoop install avr-gcc
scoop install avrdude
配置 VSCode
- 安装 VSCode 的 Go 语言插件和 TinyGo 插件,重启 VSCode
- 打开 Go 语言的项目,在底部选择编译目标(比如
TinyGo: arduino-nano
),然后重启 VSCode
配置完毕后,可以获得machine
库的代码提示
官方示例代码
package main
import (
"machine"
"time"
)
func main() {
led := machine.LED
led.Configure(machine.PinConfig{Mode: machine.PinOutput})
for {
led.Low()
time.Sleep(time.Millisecond * 500)
led.High()
time.Sleep(time.Millisecond * 500)
}
}
以 Arduino Nano 为例
tinygo flash -target=arduino-nano
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK