;; ------------------------------------------------------------ ;; ;; Blink.wat ;; (c) 2025 RIoT Secure AB ;; ;; This module implements the classic Arduino "Blinky.ino" ;; sketch using WebAssembly host functions. It toggles the ;; built-in LED on pin 13 with a 1-second delay between states. ;; ;; Host functions expected: ;; (import "brawl:device/gpio" "pinMode" (func ...)) ;; (import "brawl:device/gpio" "digitalWrite" (func ...)) ;; (import "brawl:device/sys" "delay" (func ...)) ;; ;; Entry point: ;; (start $start) -- calls setup() once, then repeatedly loop() ;; ;; ------------------------------------------------------------ (module ;; --- WASI imports --- (import "brawl:device/gpio" "pinMode" (func $pinMode (param i32 i32))) (import "brawl:device/gpio" "digitalWrite" (func $digitalWrite (param i32 i32))) (import "brawl:device/sys" "delay" (func $delay (param i32))) ;; --- ;; void setup() { ;; pinMode(13, OUTPUT); ;; } (func $setup i32.const 13 i32.const 1 call $pinMode ) ;; --- ;; void loop() { ;; digitalWrite(13, HIGH); ;; delay(1000); ;; digitalWrite(13, LOW); ;; delay(1000); ;; } (func $loop i32.const 13 i32.const 1 call $digitalWrite i32.const 1000 call $delay i32.const 13 i32.const 0 call $digitalWrite i32.const 1000 call $delay ) ;; --- WASM Entry Point ;; void start() { ;; setup(); ;; while (1) { ;; loop(); ;; } ;; } (func $start call $setup (loop $forever call $loop br $forever ) ) (export "start" (func $start)) (start $start) ) ;; ------------------------------------------------------------