• Great! There's a nicer explanation of using Chrome Serial here: https://developer.chrome.com/apps/app_serial

    And Google have an example app that includes talking to the Arduino and turning a light on and off: https://github.com/GoogleChrome/chrome-app-samples/tree/master/serial/ledtoggle#readme

    If you were using that on an Arduino as they intended, you'd have to program the Arduino first with this code, but on Espruino you can basically change this line from:

    var is_on = false;
    document.querySelector('button').addEventListener('click', function() {
      is_on = !is_on;
      connection.send(is_on ? 'y' : 'n');
    });
    

    to

    var is_on = false;
    document.querySelector('button').addEventListener('click', function() {
      is_on = !is_on;
      connection.send("digitalWrite(LED1, "+(is_on ? '1' : '0')+");\n");
    });
    

    So instead of sending simple data, you can actually send JavaScript, which is then executed by the Espruino itself...

    Note: you'll have to click the button 3 times before anything happens - if you want to fix that, replace:

    connection.send("hello arduino");
    

    with:

    connection.send("hello espruino\n");
    

    as because there was no new line sent before, it won't be executed, and the first button press will actually execute hello arduinodigitalWrite(LED1,1); - which won't work!

About

Avatar for Gordon @Gordon started