I have a little test script running fone when connected to USB:
var s = require("servo").connect(B13);
var curBuff = "";
Serial1.on('data', function (data) {
try{
if (data==","){
s.move(parseFloat(curBuff));
curBuff = "";
}
else{
curBuff += data;
}
}
catch(err){
}
});
// keep track of the next LED
var next_LED = 1;
// keep track of the ID, see later
var timeout_ID;
function swap() {
// remove the timeout to turn of all LEDs when the user pressed the button
if (timeout_ID !== undefined) {
clearTimeout(timeout_ID);
}
// determine which LED to turn on/off
switch(next_LED) {
case 1:
LED3.write(1);
LED1.write(0);
s.move(0.5);
break;
case 2:
LED2.write(1);
LED3.write(0);
s.move(0);
break;
case 3:
LED1.write(1);
LED2.write(0);
s.move(1);
break;
}
// determine the next LED to turn on
next_LED = Math.wrap(next_LED, 3) + 1;
// prepare a timeout to turn off all LEDs after a while
// we capture the ID here, so that we can use it in a next call to this function
timeout_ID = setTimeout(function () { LED1.write(0); LED2.write(0); LED3.write(0); timeout_ID = undefined; }, 5000);
}
setWatch(swap, BTN1, {repeat:true, edge:"rising"});
If I send messages to the bluetooth connection from an app on my phone, first a string of a float (e.g. '0.1') then post another BT message containing just a comma ',' the servo moves.
I can disconnect from the WebIDE. It still works.
However! If I unplug the USB, I get a BT message back from the board to my phone:
'Console Moved from USB'
Now it fails to work. I send it the float, it echos it back. I send the comma, its sends error:
"Uncaught SyntaxError: Got ',' expected EOF at line 1 col 1
,
^"
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hi
I have a little test script running fone when connected to USB:
If I send messages to the bluetooth connection from an app on my phone, first a string of a float (e.g. '0.1') then post another BT message containing just a comma ',' the servo moves.
I can disconnect from the WebIDE. It still works.
However! If I unplug the USB, I get a BT message back from the board to my phone:
'Console Moved from USB'
Now it fails to work. I send it the float, it echos it back. I send the comma, its sends error:
"Uncaught SyntaxError: Got ',' expected EOF at line 1 col 1
,
^"
Any help appreciated. :)
Phil