1
+ @external ( "arduino" , "millis" )
2
+ declare function millis ( ) : u32 ;
3
+
4
+ @external ( "arduino" , "delay" )
5
+ declare function delay ( ms : u32 ) : void ;
6
+
7
+ @external ( "arduino" , "pinMode" )
8
+ declare function pinMode ( pin : u32 , mode : u32 ) : void ;
9
+
10
+ @external ( "arduino" , "digitalWrite" )
11
+ declare function digitalWrite ( pin : u32 , value : u32 ) : void ;
12
+
13
+ @external ( "arduino" , "getPinLED" )
14
+ declare function getPinLED ( ) : u32 ;
15
+
16
+ @external ( "arduino" , "serialLog" )
17
+ declare function println ( output : string ) : void ;
18
+ //declare function println(output: usize, len: i32): void;
19
+ //declare function println(output: string, len: i32): void;
20
+
21
+ function log ( out : string ) : void {
22
+ //println(out, out.length) // <- Only first letter arrives, but lenght is correct
23
+ println ( out ) ;
24
+ //println(out); // <- Only first letter arrives
25
+ //String.UTF16.encode(out) // <- Just referencing this crashes
26
+ //println(changetype<usize>(String.UTF8.encode(out, true)), String.UTF8.byteLength(out, true)); // <- Crash
27
+ //println(String.UTF8.encode(out, true), String.UTF8.byteLength(out, true)); // <- Crash
28
+ }
29
+
30
+ const LOW : u32 = 0 ;
31
+ const HIGH : u32 = 1 ;
32
+
33
+ const INPUT : u32 = 0x0 ;
34
+ const OUTPUT : u32 = 0x1 ;
35
+ const INPUT_PULLUP : u32 = 0x2 ;
36
+
37
+ let LED : u32 = - 1 ;
38
+
39
+ function setup ( ) : void {
40
+ LED = getPinLED ( ) ;
41
+ pinMode ( LED , OUTPUT ) ;
42
+ }
43
+
44
+ function run ( ) : void {
45
+ log ( 'From Web Assembly' )
46
+ digitalWrite ( LED , HIGH ) ;
47
+ delay ( 1000 ) ;
48
+ digitalWrite ( LED , LOW ) ;
49
+ delay ( 1000 ) ;
50
+ }
51
+
52
+ /*
53
+ * Entry point
54
+ */
55
+ export function _start ( ) : void {
56
+ setup ( ) ;
57
+ while ( 1 ) run ( ) ;
58
+ }
0 commit comments