digitalWrite(array,1) bug?

Posted on
  • Test performed on Espruino Original Board and STM F4 with 1v85.

    var pins = [C7,C8];
    
    digitalWrite(pins,0); // Sets both pins to low
    digitalWrite(pins,1); // Only sets C8 to high
    
    digitalWrite(pins[0],0);digitalWrite(pins[1], 0); // Works as expected
    digitalWrite(pins[0],1);digitalWrite(pins[1], 1);  // Works as expected
    

    Best regards,
    Marten

  • Unless I'm missing something, this is all documented in the digitalWrite reference?

    digitalWrite([LED1,LED2], 0) // both off
    digitalWrite([LED1,LED2], 1) // LED2
    digitalWrite([LED1,LED2], 2) // LED1
    digitalWrite([LED1,LED2], 3) // LED1 + LED2
    

    Basically if you put an array in then you can write the pins directly with a binary number - it's hugely useful for things like LED displays, where you might want to write values to several pins at once.

  • You're correct - I didn't read the note carefully enough. Sorry.

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

digitalWrite(array,1) bug?

Posted by Avatar for Maarten @Maarten

Actions