diff --git a/Makefile b/Makefile index 83be0143..90e8cf65 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ all: tgo tgo: build/tgo -.PHONY: all tgo run-hello run-blinky clean fmt gen-device gen-device-nrf +.PHONY: all tgo run-test run-blinky run-blinky2 clean fmt gen-device gen-device-nrf # Custom LLVM toolchain. LLVM := $(shell go env GOPATH)/src/github.com/aykevl/llvm/bindings/go/llvm/workdir/llvm_build/bin/ @@ -56,11 +56,12 @@ endif -run-hello: build/hello - ./build/hello +run-test: build/test + ./build/test -run-blinky: build/blinky - ./build/blinky +run-blinky: run-blinky2 +run-blinky2: build/blinky2 + ./build/blinky2 ifeq ($(TARGET),pca10040) flash-%: build/%.hex @@ -74,7 +75,7 @@ clean: @rm -rf build fmt: - @go fmt . ./src/examples/hello + @go fmt . ./src/examples/test @go fmt ./src/runtime/*.go gen-device: gen-device-nrf diff --git a/README.markdown b/README.markdown index 56f2f372..6e9168b8 100644 --- a/README.markdown +++ b/README.markdown @@ -131,7 +131,7 @@ development. After LLVM has been built, you can run an example with: - make run-hello + make run-test For a blinky example on the PCA10040 development board, do this: diff --git a/src/examples/blinky1/blinky1.go b/src/examples/blinky1/blinky1.go new file mode 100644 index 00000000..8889cb69 --- /dev/null +++ b/src/examples/blinky1/blinky1.go @@ -0,0 +1,20 @@ +package main + +// This is the most minimal blinky example and should run almost everywhere. + +import ( + "machine" + "runtime" +) + +func main() { + led := machine.GPIO{machine.LED} + led.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT}) + for { + led.Low() + runtime.Sleep(runtime.Millisecond * 500) + + led.High() + runtime.Sleep(runtime.Millisecond * 500) + } +} diff --git a/src/examples/blinky/blinky.go b/src/examples/blinky2/blinky2.go similarity index 71% rename from src/examples/blinky/blinky.go rename to src/examples/blinky2/blinky2.go index 1479725b..417ca604 100644 --- a/src/examples/blinky/blinky.go +++ b/src/examples/blinky2/blinky2.go @@ -1,5 +1,10 @@ package main +// This blinky is a bit more advanced than blink1, with two goroutines running +// at the same time and blinking a different LED. The delay of led2 is slightly +// less than half of led1, which would be hard to do without some sort of +// concurrency. + import ( "machine" "runtime" diff --git a/src/examples/hello/hello.go b/src/examples/test/test.go similarity index 97% rename from src/examples/hello/hello.go rename to src/examples/test/test.go index 1fa8886c..87143721 100644 --- a/src/examples/hello/hello.go +++ b/src/examples/test/test.go @@ -1,5 +1,7 @@ package main +// This file is here to test features of the Go compiler. + import "unicode" type Thing struct {