-
No, it's still async. In Espruino you can take the block "Wait BTN1 both edge do", that is basically the same as an await. And ofc the "sleep" functions implemented in ES7 are still async, if there's any function triggered while a "sleep" function is "active" that function will be executed.
The give an example:
-You have the LED "toggle" function, switching an LED on and off every 1 second, either with setInterval() or with a ES7 "sleep" function.
-You have another "fancy" function to do some fancy stuff, taking 3 seconds.
Whenever the "fancy" function is executed your LED will stay on (or off) for 3..4 seconds, because the "toggle" function is only executed after the "fancy" function has completed, because there's no multitasking and things run async. -
The blocks "After n seconds do" and "Every n seconds do" are suited for the task, like this:
Every 2 seconds do ----After 1 seconds do --------print "LED 1 off" ----print "LED 2 on"
And yes, it first prints "LED 1 on" and then "LED 1 off", and that makes complete sense. If you tell someone to switch the light out after 1 minute from now on, and then to switch the lights on immediately the exact same thing will happen: Lights on first, then lights off. So I'd say even kids can understand this.
Now duplicate the block, multiply the numbers by 2.5 and update the text. The kids will see the real power of async programming. You could toggle one LED at 1 Hz and another one at 2.5 Hz. How would you do this with a while loop using waits?
The wait block should be removed for Espruino as it doesn't do anything useful, Javascript being an async progamming language.
-
I flash on Windows with these settings:
https://germanwarez.blogspot.com/2017/04/installing-espruino-to-esp8266-on.html -
@Thijsmans: Either there was a huge improvement in espruino (2v03), or your WIFI AP and DHCP server are both slow. For me using DHCP the connection is usually up in 2.18 seconds. I tested also with channel and bssid, but this didn't change anything for me.
My code:
var wifi = require("Wifi"); var test = function() { wifi.disconnect(); var startTime = getTime(); wifi.connect(wifi.getDetails().ssid,{password: wifi.getDetails().password}, function(err) { var endTime = getTime(); var duration = endTime - startTime; if (err) { console.log('Wifi setup error, duration/s=' + duration ); } else { console.log('Wifi connection is up, duration/s=' + duration ); } }); }
I assume the tracks are AC, there's a rectifier in the car (#4 you see the 4 diodes) and the motors are DC.
I'd use a standard rc car ESC with BEC for 3S or 4S, depending on the DC voltage available after the rectifier. (There are ESCs for DC motors without aluminum cooling block and fan). These ESCs have the PWM already build in, so no need to build your own PWM software and hardware.
Then just modify your board to work with the CR2031 as backup to avoid resets, and power it from the 5V BEC.
To control the ESC: