mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-08 21:13:39 +00:00
2a20c0c7f0
time.Sleep now compiles on all systems, so lets use that. Additionally, do a few improvements in time unit handling for the scheduler. This should lead to somewhat longer sleep durations without wrapping (on some platforms). Some examples got smaller, some got bigger. In particular, code using the scheduler got bigger and the blinky1 example got smaller (especially on Arduino: 380 -> 314 bytes).
45 lines
843 B
Go
45 lines
843 B
Go
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"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
go led1()
|
|
led2()
|
|
}
|
|
|
|
func led1() {
|
|
led := machine.GPIO{machine.LED}
|
|
led.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
|
for {
|
|
println("+")
|
|
led.Low()
|
|
time.Sleep(time.Millisecond * 1000)
|
|
|
|
println("-")
|
|
led.High()
|
|
time.Sleep(time.Millisecond * 1000)
|
|
}
|
|
}
|
|
|
|
func led2() {
|
|
led := machine.GPIO{machine.LED2}
|
|
led.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
|
for {
|
|
println(" +")
|
|
led.Low()
|
|
time.Sleep(time.Millisecond * 420)
|
|
|
|
println(" -")
|
|
led.High()
|
|
time.Sleep(time.Millisecond * 420)
|
|
}
|
|
}
|