Created
August 22, 2019 14:48
-
-
Save jesselang/acae8cebfafba51bef3810089541112d to your computer and use it in GitHub Desktop.
Playing around with https://play.tinygo.org
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"machine" | |
"time" | |
) | |
const pattern = "... ––– ..." | |
const interval = time.Second / 3 | |
func space() { | |
led.Low() | |
time.Sleep(interval) | |
} | |
func dot() { | |
led.High() | |
time.Sleep(interval) | |
led.Low() | |
time.Sleep(interval) | |
} | |
func dash() { | |
led.High() | |
time.Sleep(interval * 3) | |
led.Low() | |
time.Sleep(interval) | |
} | |
var ( | |
// Patrick approves | |
signals = map[rune]func(){ | |
' ': space, | |
'.': dot, | |
'-': dash, | |
'–': dash, | |
} | |
) | |
const led = machine.LED | |
func main() { | |
println("Hello, TinyGo") | |
led.Configure(machine.PinConfig{Mode: machine.PinOutput}) | |
for _, v := range pattern { | |
println(string(v)) | |
signals[v]() | |
} | |
led.Low() | |
time.Sleep(interval) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment