Loopback2.js 22 Aug 2016
Used the Loopback devices to allow the USB port to act as program input.
Commands sent to the USB port trigger sub commands that get sent to the Espruino console.
0: Exit,
1: LEDon
2: LEDoff
The left pane of the WebIde or a terminal program connected to the USB port can be used to send the commands.
//Loopback2.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;
Sp1.setup(115200);
Sp2.setup(115200);
LoopbackB.setup(115200);
LoopbackB.setConsole();
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");
break;
case "2"://LED off
Sp2.print("digitalWrite(B12,0);\n\r");
Sp1.print("digitalWrite(B12,0);\n\r");
break;
case"0"://Exit
Sp2.print("reset();\n\r");
Sp2.print("USB.setConsole();\n\r");
Sp1.print("USB.setConsole();\n\r");
}//end switch
});
The output:
>echo(0);
Enter 1 to turn the LED on:
Enter 2 to turn the LED off:
Enter 0 to Exit:
echo(1)
1
digitalWrite(B12,1);
2
digitalWrite(B12,0);
1
digitalWrite(B12,1);
2
digitalWrite(B12,0);
1
digitalWrite(B12,1);
2
digitalWrite(B12,0);
1
digitalWrite(B12,1);
2
digitalWrite(B12,0);
1
digitalWrite(B12,1);
2
digitalWrite(B12,0);
1
digitalWrite(B12,1);
2
digitalWrite(B12,0);
0
USB.setConsole();
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.
Loopback2.js 22 Aug 2016
Used the Loopback devices to allow the USB port to act as program input.
Commands sent to the USB port trigger sub commands that get sent to the Espruino console.
0: Exit,
1: LEDon
2: LEDoff
The left pane of the WebIde or a terminal program connected to the USB port can be used to send the commands.
The output:
1 Attachment