• Hi,

    The issue you have is that Espruino doesn't keep built-in variables/functions in the symbol table, because there's just not enough RAM. That means that while you can access a variable or function by name, you can't access it as if it were an actual member of the object. It's something I'm hoping to fix - there is a bug open for this but it's a reasonably big change.

    However nothing stops you from doing:

    leds = [LED1,LED2,LED3];
    leds[1].write(1);
    

    or even:

    leds = [LED1,LED2,LED3];
    digitalWrite(leds, 0b100);
    digitalWrite(leds, 0b010);
    digitalWrite(leds, 0b001);
    

    Or if you're still absolutely set on accessing everything by strings, you can do:

    led = function (n) { return eval("LED"+n); }
    

    Note that because Espruino executes from source, there isn't much overhead to running eval

    Hope that helps...

About

Avatar for Gordon @Gordon started