Skip to content

Commit b2b7479

Browse files
committed
GoLang: add print and greeting
1 parent 9256f90 commit b2b7479

File tree

4 files changed

+318
-46
lines changed

4 files changed

+318
-46
lines changed

examples_pio/Wasm_Advanced/wasm_apps/tinygo/app.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package main
22

3+
import (
4+
"strconv"
5+
)
6+
37
/*
48
* Arduino API
59
*/
@@ -33,6 +37,31 @@ func digitalWrite(pin, value uint)
3337
//go:export getPinLED
3438
func getPinLED() uint
3539

40+
//go:wasm-module arduino
41+
//go:export print
42+
func print(s string)
43+
44+
//go:wasm-module arduino
45+
//go:export getGreeting
46+
func _getGreeting(buf *byte, maxlen uint)
47+
48+
func println(s string) {
49+
print(s + "\n")
50+
}
51+
52+
func getGreeting() string {
53+
var buf = make([]byte, 64)
54+
_getGreeting(&buf[0], 64)
55+
// Find '\0'
56+
n := -1
57+
for i, b := range buf {
58+
if b == 0 {
59+
break
60+
}
61+
n = i
62+
}
63+
return string(buf[:n+1])
64+
}
3665

3766
/*
3867
* App
@@ -42,9 +71,15 @@ var LED = getPinLED()
4271

4372
func setup() {
4473
pinMode(LED, 1)
74+
75+
println("TinyGo is running")
76+
println("Greeting: " + getGreeting())
4577
}
4678

4779
func loop() {
80+
t := millis()
81+
println(strconv.FormatUint(uint64(t), 10))
82+
4883
digitalWrite(LED, HIGH)
4984
delay(100)
5085
digitalWrite(LED, LOW)
2.78 KB
Binary file not shown.

0 commit comments

Comments
 (0)