forked from TOPLLab/WARDuino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π Add website examples (TOPLLab#209)
* π Add website examples * Add build script for Rust examples
- Loading branch information
Showing
41 changed files
with
855 additions
and
385 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,3 +33,5 @@ _deps | |
|
||
core | ||
venv | ||
|
||
*.wasm |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
# Examples | ||
|
||
This folder contains multiple different example programs for WARDuino. | ||
All WebAssembly text files (.wat) from the examples can be run without additional hardware, by using the emulated version of WARDuino. | ||
This folder contains the code for all examples from the [tutorials](https://topllab.github.io/WARDuino/guide/examples/) from the documentation website. | ||
|
||
Additionally, the `wat` folder contains a simple example in textual WebAssembly, which relies on no other higher-level languages. | ||
|
||
## Running the examples | ||
|
||
All WebAssembly binaries (.wasm) from the examples can be run without additional hardware, by using the emulated version of WARDuino. | ||
This version is packaged as a command line interface. | ||
|
||
```bash | ||
./wdcli --file example.wat | ||
./wdcli --file example.wasm | ||
``` | ||
|
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,32 @@ | ||
{ | ||
"entries": [ | ||
"src/main.ts" | ||
], | ||
"targets": { | ||
"debug": { | ||
"debug": true, | ||
"outFile": "bin/main.debug.wasm", | ||
"textFile": "bin/main.debug.wast" | ||
}, | ||
"release": { | ||
"binaryFile": "build/smartlamp.wasm", | ||
"textFile": "build/smartlamp.wat", | ||
"sourceMap": false, | ||
"optimize": true | ||
"converge": true, | ||
"optimizeLevel": 3, | ||
"outFile": "bin/main.wasm", | ||
"shrinkLevel": 2 | ||
} | ||
}, | ||
"options": {} | ||
"options": { | ||
"disable": [ | ||
"mutable-globals", | ||
"sign-extension", | ||
"nontrapping-f2i", | ||
"bulk-memory" | ||
], | ||
"exportTable": true, | ||
"exportRuntime": false, | ||
"maximumMemory": 2, | ||
"noAssert": false, | ||
"runtime": "stub", | ||
"sourceMap": true | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {analogRead, | ||
analogWrite, | ||
delay, | ||
print} from "as-warduino/assembly"; | ||
|
||
const IN: u32 = 13; | ||
const OUT: u32 = 9; | ||
|
||
function map(value: u32, x1: u32, y1: u32, x2: u32, y2: u32): u32 { | ||
return <u32>((value - x1) * (y2 - x2) / (y1 - x1) + x2); | ||
} | ||
|
||
export function main(): void { | ||
const value = analogRead(IN); | ||
|
||
const output = map(value, 0, 1023, 0, 255); | ||
|
||
analogWrite(OUT, output); | ||
|
||
print(`sensor = ${value}\t output = ${output}`); | ||
delay(1); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {analogRead, delay, print} from "as-warduino/assembly"; | ||
|
||
export function main(): void { | ||
const value = analogRead(13); | ||
print(value); | ||
delay(1); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Blinking LED example | ||
import {pinMode, PinMode, PinVoltage, | ||
digitalWrite, delay} from "as-warduino/assembly"; | ||
|
||
export function main(): void { | ||
const led = 26; | ||
const pause: u32 = 1000; | ||
|
||
pinMode(led, PinMode.OUTPUT); | ||
|
||
while (true) { | ||
digitalWrite(led, PinVoltage.HIGH); | ||
delay(pause); | ||
digitalWrite(led, PinVoltage.LOW); | ||
delay(pause); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Blinking LED example | ||
import {pinMode, PinMode, PinVoltage, | ||
digitalWrite, delay} from "as-warduino/assembly"; | ||
|
||
export function main(): void { | ||
const led: u32 = 26; | ||
const pause: u32 = 1000; | ||
|
||
pinMode(led, PinMode.OUTPUT); | ||
|
||
while (true) { | ||
digitalWrite(led, PinVoltage.HIGH); | ||
delay(pause); | ||
digitalWrite(led, PinVoltage.LOW); | ||
delay(pause); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { | ||
delay, | ||
digitalRead, | ||
digitalWrite, | ||
InterruptMode, | ||
interruptOn, | ||
pinMode, | ||
PinMode, | ||
PinVoltage | ||
} from "as-warduino/assembly"; | ||
|
||
const button = 25; | ||
const led = 26; | ||
|
||
function invert(voltage: PinVoltage): PinVoltage { | ||
switch (voltage) { | ||
case PinVoltage.LOW: | ||
return PinVoltage.HIGH; | ||
case PinVoltage.HIGH: | ||
default: | ||
return PinVoltage.LOW; | ||
} | ||
} | ||
|
||
function toggleLED(_topic: string, _payload: string): void { | ||
// Get current status of LED | ||
let status = digitalRead(led); | ||
// Toggle LED | ||
digitalWrite(led, invert(status)); | ||
} | ||
|
||
export function main(): void { | ||
pinMode(button, PinMode.INPUT); | ||
pinMode(led, PinMode.OUTPUT); | ||
|
||
interruptOn(button, InterruptMode.FALLING, toggleLED); | ||
|
||
while (true) { | ||
delay(1000); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const BUTTON = 25; | ||
export const LED = 26; | ||
export const SSID = "local-network"; | ||
export const PASSWORD = "network-password"; | ||
export const CLIENT_ID = "random-mqtt-client-id"; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {pinMode, PinMode} from "as-warduino/assembly"; | ||
import * as config from "./config"; | ||
|
||
export function main(): void { | ||
let led = config.LED; | ||
pinMode(led, PinMode.OUTPUT); | ||
} |
Oops, something went wrong.