-->
Page 1 of 1

smart.js in practice

PostPosted: Thu Oct 08, 2015 3:30 pm
by jankop
It's not easy. No documentation, examples of dysfunctional and nearly none.
But first program in smart.js I wrote. It cost me a few hours of my time, because everything is different than declaring Cesanta.
Tested with smart.js APLHA2:
Code: Select all// JavaScript - blinkig LED on GPIO0
// test GPIO.setmode(), GPIO.write() and GPIO.read()
var led =1;
var pin =0; // GPIO0 = 0, GPIO1 = 1 (blueLED)... etc
var mod =0; // 0 = I/O, 1 = INP, 2 = OUT, 3 = Interrupt
var pul =1; // 0 = floating, 1 = pullup, 2 = pulldown resistor
GPIO.setmode(pin, mod, pul)
function blink() { GPIO.write(pin,led);
    if (led==1) {led=0} else {led=1}; print(pin,mod,pul,GPIO.read(pin));
     setTimeout(blink, 1000);}
blink()


Note: for start of program aply File.eval('file-name.js')

Re: smart.js in practice

PostPosted: Thu Oct 08, 2015 3:48 pm
by kolban
I had a go at writing the same app in Espruino JavaScript running on the ESP8266 and came up with:

Code: Select allvar led = true;
var pin = new Pin(0);

function blink() {
  digitalWrite(pin, led);
  print("Pin" + pin + " = " + led);
  led = !led;
  setTimeout(blink, 1000);
}
blink();


As an alternative to calling:

Code: Select alldigitalWrite(pin, led);


one can also call:

Code: Select allpin.write(led);

Re: smart.js in practice

PostPosted: Thu Oct 08, 2015 4:00 pm
by jankop
It's very similar!

Re: smart.js in practice

PostPosted: Sat Nov 14, 2015 1:28 pm
by Sergey Lyubka
jankop wrote:It's not easy. No documentation, examples of dysfunctional and nearly none.
Note: for start of program aply File.eval('file-name.js')


Speaking on behalf of Cesanta - I am the CTO of the company.
We were at alpha stage, and yes - rough and unstable at that moment.
However, we've improved things a lot, and work is in progress!

Examples, including blink example, at https://www.cesanta.com/developer/smart ... nk_example
I'd appreciate the feedback.