//Loopback3.js
//22 Aug 2016
//use the left pane of the WebIde or
//use putty or other termial program on com assigned to USB
//use webide to load and run the program
//disconnect webide
//start putty on com port at 115200,8 no flow control
//typing in putty should appear followed by connect in putty screen
var Sp1=USB;
var Sp2=LoopbackA;
function run(){
Sp1.setup(115200);
Sp2.setup(115200);
LoopbackB.setup(115200);
LoopbackB.setConsole();
}
function menu(){
Sp1.print("Enter 1 to turn the LED on:\n\r");
Sp1.print("Enter 2 to turn the LED off:\n\r");
Sp1.print("Enter 0 to Exit:\n\r");
}
Sp1.on('data', function (data) {
Sp1.print(data+"\n\r");
switch(data){
case "1"://LED on
Sp2.print("digitalWrite(B12,1);\n\r");
Sp1.print("digitalWrite(B12,1);\n\r");
menu();
break;
case "2"://LED off
Sp2.print("digitalWrite(B12,0);\n\r");
Sp1.print("digitalWrite(B12,0);\n\r");
menu();
break;
case"0"://Exit
Sp2.print("USB.setConsole();\n\r");
}//end switch
});
function test(){
run();
menu();
}
var a=setInterval (function () {
test();
clearInterval(a);
}, 1000);
The output:
>echo(0);
=undefined
-> LoopbackB
Enter 1 to turn the LED on:
Enter 2 to turn the LED off:
Enter 0 to Exit:
1
digitalWrite(B12,1);
Enter 1 to turn the LED on:
Enter 2 to turn the LED off:
Enter 0 to Exit:
2
digitalWrite(B12,0);
Enter 1 to turn the LED on:
Enter 2 to turn the LED off:
Enter 0 to Exit:
0
<- LoopbackB
=undefined
=undefined
>1
=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.
Some improvements:
The output:
1 Attachment