1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Adafruit Trinket M0でTinyGo(外部LED編)

Posted at

#はじめに
第2回に続き、今回はTinyGoに外部LEDを接続して点滅させてみる
#動作環境

  • OS: macOS 10.15.3
  • Go: 1.13.8
  • TinyGo: 0.12.0
  • マイコン: Adafruit Trinket M0
  • LED: Grove Red LED

LEDはスイッチサイエンスマルツあたりで通販可能

#配線

Trinket M0 Grove LED
D0 SIG
- NC
3V3 VCC
GND GND

D0の代わりにD1〜D4でもOK

#実行コード

main.go
package main

import (
	"machine"
	"time"
)

func main() {
	//led = D0 or D1 or D2 or D3
	led := machine.D0
	led.Configure(machine.PinConfig{Mode: machine.PinOutput})
	for {
		led.Low()
		time.Sleep(time.Millisecond * 500)

		led.High()
		time.Sleep(time.Millisecond * 500)
	}
}

#ビルド&書き込み
###パターン1. Macでビルド&書き込み
MacにインストールしたTinyGoを使ってビルドから書き込みまで一気に実行

$ tinygo flash -target trinket-m0 ./main.go

###パターン2. Dockerでビルド&Macから書き込み
Mac上でDockerを使ってビルドして、書き込みはMacから実行
Trinket M0はUSBマスストレージとして扱えるので、ビルドで生成されたUF2ファイルをドラッグ&ドロップで書き込み

$ docker run --rm -v $(pwd):/src -w /src tinygo/tinygo:0.12.0 \
tinygo build -o /src/flash.uf2 -size=short -target trinket-m0 ./main.go

#実行結果
IMG_20200310_213652.jpg

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?