Skip to content

Commit 4c24bae

Browse files
committed
Split go example into arduino/main packages
1 parent a4571ee commit 4c24bae

File tree

4 files changed

+339
-337
lines changed

4 files changed

+339
-337
lines changed

examples_pio/Wasm_Advanced/wasm_apps/tinygo/app.go

Lines changed: 11 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,27 @@
11
package main
22

33
import (
4+
. "./arduino"
45
"strconv"
56
)
67

7-
/*
8-
* Arduino API
9-
*/
10-
11-
const (
12-
LOW = 0
13-
HIGH = 1
14-
15-
INPUT = 0
16-
OUTPUT = 1
17-
INPUT_PULLUP = 2
18-
)
19-
20-
//go:wasm-module arduino
21-
//go:export millis
22-
func millis() uint
23-
24-
//go:wasm-module arduino
25-
//go:export delay
26-
func delay(ms uint)
27-
28-
//go:wasm-module arduino
29-
//go:export pinMode
30-
func pinMode(pin, mode uint)
31-
32-
//go:wasm-module arduino
33-
//go:export digitalWrite
34-
func digitalWrite(pin, value uint)
35-
36-
//go:wasm-module arduino
37-
//go:export getPinLED
38-
func getPinLED() uint
39-
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)
50-
print("\n")
51-
}
52-
53-
func getGreeting() string {
54-
var buf = make([]byte, 64)
55-
_getGreeting(&buf[0], 64)
56-
// Find '\0'
57-
n := -1
58-
for i, b := range buf {
59-
if b == 0 {
60-
break
61-
}
62-
n = i
63-
}
64-
return string(buf[:n+1])
65-
}
66-
67-
/*
68-
* App
69-
*/
70-
71-
var LED = getPinLED()
8+
var LED = GetPinLED()
729

7310
func setup() {
74-
pinMode(LED, 1)
11+
PinMode(LED, 1)
7512

76-
println("TinyGo is running")
77-
println("Greeting: " + getGreeting())
13+
Println("TinyGo is running")
14+
Println("Greeting: " + GetGreeting())
7815
}
7916

8017
func loop() {
81-
time := millis()
82-
println(strconv.FormatUint(uint64(time), 10))
18+
time := Millis()
19+
Println(strconv.FormatUint(uint64(time), 10))
8320

84-
digitalWrite(LED, HIGH)
85-
delay(100)
86-
digitalWrite(LED, LOW)
87-
delay(900)
21+
DigitalWrite(LED, HIGH)
22+
Delay(100)
23+
DigitalWrite(LED, LOW)
24+
Delay(900)
8825
}
8926

9027
/*
98 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)