How to select the buildin led?

Posted on
  • So far Espruino has been awesome but as a beginner I have some issues wrapping my head around targeting the pins. In the documentation I can see

    NodeMCU.A0
    NodeMCU.D0
    NodeMCU.D1
    NodeMCU.D10
    NodeMCU.D2
    NodeMCU.D3
    NodeMCU.D4
    NodeMCU.D5
    NodeMCU.D6
    NodeMCU.D7
    NodeMCU.D8
    NodeMCU.D9

    However there is no mention of the buildin led on the board. How can I select that?
    Also I don't know how I can select the other pins for example S1 S2 EN and RX.

    Appreciate it.

  • @user130486,

    you should be able override it just like that var LED1 = NodeMCU.D2; to put NodeMCU.D2 on LED1 (or just any other (var) name). Since it is a pin, it 'understands' .set() and .reset() and all other pin related 'methods' as documented in https://www.espruino.com/Reference#Pin documentation. Since Espruino boards have the LEDs known and (may) preset pin mode, you may need to do that too with the assignment, such as pinMode(NodeMCU.D2,"output"). --- Let us know if it works... your board's built-in LWD - if there is one on any of the pins - or to which pin you will connect the LED w/ resistor - will define the code detail.

  • I actually managed to get the built-in LED on with :

    var led      = NodeMCU.D4;  // built-in LED
    var state    = true;        // LED switched on by default
    var duration = 500;         // blink the LED every 500 ms
    
    setInterval(function() {
      digitalWrite(led, state);
      state = !state;           // toggle LED state
    }, duration);
    

    Thank you so much for guiding me

  • ...very self explanatory! Thanks for sharing.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

How to select the buildin led?

Posted by Avatar for user130486 @user130486

Actions