Add goroutines and function pointers

This commit is contained in:
Ayke van Laethem
2018-06-07 14:48:24 +02:00
parent 8df220a53b
commit 0168bf7797
10 changed files with 796 additions and 59 deletions
+26 -7
View File
@@ -7,15 +7,34 @@ import (
)
func main() {
led := machine.GPIO{17} // LED 1 on the PCA10040
go led1()
led2()
}
func led1() {
led := machine.GPIO{machine.LED}
led.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
for {
println("LED on")
led.Set(false)
runtime.Sleep(runtime.Millisecond * 500)
println("+")
led.Low()
runtime.Sleep(runtime.Millisecond * 1000)
println("LED off")
led.Set(true)
runtime.Sleep(runtime.Millisecond * 500)
println("-")
led.High()
runtime.Sleep(runtime.Millisecond * 1000)
}
}
func led2() {
led := machine.GPIO{machine.LED2}
led.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
for {
println(" +")
led.Low()
runtime.Sleep(runtime.Millisecond * 420)
println(" -")
led.High()
runtime.Sleep(runtime.Millisecond * 420)
}
}
+10
View File
@@ -25,6 +25,16 @@ func main() {
printItf(5)
printItf(byte('x'))
printItf("foo")
runFunc(hello) // must be indirect to avoid obvious inlining
}
func runFunc(f func()) {
f()
}
func hello() {
println("hello from function pointer!")
}
func strlen(s string) int {