Getting Started
Linuxduino is a port of the Arduino Programing language for embedded systems running Linux (e.g., Raspberry PI, DragonBoard 410c, even your own Linux Computer). Linuxduino is a C++ library and has been ported to JavaScript using WebAssembly.
Install
JavaScript
linuxduino requires Node v8 or above
npm install linuxduino
C++
todo
Usage
Blink an LED in Javascript
const linuxduino = require('linuxduino');
// Test digitalWrite
(async() => {
// Wait for wasm file
await linuxduino.ready;
var ledPin = 4; // Embedded board GPIO Number
linuxduino.pinMode(ledPin, linuxduino.OUTPUT);
while(1) {
console.log("LED ON");
linuxduino.digitalWrite(ledPin, linuxduino.HIGH);
linuxduino.delay(1000); // Delay 1 sec
console.log("LED OFF");
linuxduino.digitalWrite(ledPin, linuxduino.LOW);
linuxduino.delay(1000); // Delay 1 sec
}
return 0;
})();
Run it
sudo node digitalWrite.js
Blink an LED in C++
#include "Linuxduino.h"
// Test digitalWrite
int main(void) {
int ledPin = 4; // Embedded board GPIO Number
pinMode(ledPin, OUTPUT);
while(1) {
printf("LED ON\n");
digitalWrite(ledPin, HIGH);
delay(1000); // Delay 1 sec
printf("LED OFF\n");
digitalWrite(ledPin, LOW);
delay(1000); // Delay 1 sec
}
return 0;
}
Run it
g++ digitalWrite.cpp -o digitalWrite -llxduino
sudo ./digitalWrite
Check the Reference to see the full list of implemented functions and examples.
Arduino style compatibility for C++
C++ programs can also use the Arduino programming style by including the
Arduino.h
instead of Linuxduino.h
header and compiling them
with -llxarduino
instad of -llxduino
. Example:
Blink an LED in C++ using the Arduino programming style.
#include "Arduino.h"
// Test Arduino style digitalWrite
int ledPin = 4; // GPIO4
void setup () {
pinMode(ledPin, OUTPUT);
}
void loop () {
printf("LED ON\n");
digitalWrite(ledPin, HIGH);
delay(1000);
printf("LED OFF\n");
digitalWrite(ledPin, LOW);
delay(1000);
}
Run it
g++ digitalWrite.cpp -o digitalWrite -llxarduino
sudo ./digitalWrite
Note that Wire.h
and SPI.h
should be included separately if Arduino.h
is used.