You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • 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);
    
About

Avatar for Gordon @Gordon started