JavaScript - усюди! Тільки нещодавно запускав один і той самий JS код в Browser, Node.js, та React Native, як уже новий виклик - Embedded системи… Спокійно, JS справиться! На цій доповіді ви дізнаєтесь, які двіжки JS працюють в дуже обмежених середовищах, хто і як це використовує в продакшні та наскільки весело розробляти софт під всякі залізяки на JS.
[Спойлер] Якщо все вийде, спробуємо відтворити мелодію Mario на звичайному Bluetooth-брелку для ключів :)
19. ● Feature-rich JS engine
● Declares nRF51822 support
(as well as many other MCUs)
● Supports Bluetooth
● Has an IDE
● Auto-minifies JS
● Provides REPL via bluetooth
● & I had some prev. experience ;)
20. BUILD IT
1. Get Espruino release from github
2. Install gcc-arm-none-eabi-5_4-2016q3 toolchain
3. Build:
BOARD=NUT2 RELEASE=1 make
-> hex file is produced
4. Flash it to the board
.:[ complete instructions ]:.
ST-Link V2 ~ $2
21. LET’S CODE
LED1.write(1); /* Turn led ON */
LED1.write(0); /* Turn led OFF */
function toggle() {
state = !state;
LED1.write(state);
}
/* Start timer */
setInterval(toggle, 500)
/* Output frequency: 1000 hz square wave */
analogWrite(D30, 0.5, { freq: 1000 } )
22. function buzz(f, duration) {
analogWrite(D30, 0.5, { freq: f } );
setTimeout(function() {
pinMode(D30, 'input');
}, duration);
}
let mario_freq = new Uint16Array([330,330,0,330,0,262,330,0,392,0,0,196,0,0, ...]);
let mario_temp = new Uint8Array([80 ,80,80,80,80,80,80,80,80,80,40,80,80,40, ...]);
let pos = 0, tmr = -1;
function step() {
let freq = mario_freq[pos];
if (freq === undefined)
return stop();
let temp = 10000/mario_temp[pos];
changeInterval(tmr, temp);
buzz(freq, temp);
pos++;
}
function stop() {
if (tmr >= 0) {
buzz(0);
clearInterval(tmr);
tmr = -1;
}
}
function play_mario() {
stop();
pos = 0;
tmr = setInterval(step, 0);
}
Not too much simplified ;)
28. Volodymyr Shymanskyy
Entrepreneur, Software & Hardware Developer, Trainer
Co-Founder of Blynk, Hackerspace Coordinator
● Lots of projects
● 10+ years in IT, 8 in outsourcing and embedded
● Master’s degree in Cybernetics
@ National Taras Shevchenko University of Kyiv
> facebook > LinkedIn > vshymanskyi@gmail.com
Disclaimer: these brands are not affiliated with current presentation or it’s topic