I think the issue you are hitting is that uart.write doesn't complete immediately. I believe it returns a promise which completes when the write has finished. So calling uart.write twice will cause you problems.
You could chain the promises, but perhaps it makes more sense to do:
cmd="";
if (avrX > 90){
cmd+="\x03\x10digitalWrite(LED1, 0), digitalWrite(D31, 0);\n");
if (avrX < 105){
cmd+="\x03\x10digitalWrite(LED1, 0),digitalWrite(D27, 0);\n");
if (avrY > 90){
cmd+="\x03\x10digitalWrite(LED1, 0),digitalWrite(D28, 0);\n");
if (avrY < 105){
cmd+="\x03\x10digitalWrite(LED1, 0),digitalWrite(D29, 0);\n");
if (cmd) uart.write(cmd);
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.
I think the issue you are hitting is that
uart.write
doesn't complete immediately. I believe it returns a promise which completes when the write has finished. So calling uart.write twice will cause you problems.You could chain the promises, but perhaps it makes more sense to do: