Using singleButton to change multiple pins at the same time

Bolt and JS noob here so sorry if this is silly. How do i use the singleButton function to change the value of multiple pins on the same click?

For example, if I want to use one button named ‘Forward’ to change pin 1 on bolt to HIGH but pin 2 to LOW, how would I do that?

singleButton({ name : “Forward”, action :“digitalWrite”, pin : {“1”:“2”}, value : {“HIGH”:“LOW”}});

  1. Connect any GND pin from the Arduino to the ground rail on your breadboard using a jumper wire.
  2. Place an LED on your breadboard, make sure to note which way the long leg is facing.
  3. Using a jumper wire, connect pin 13 from your Arduino to the breadboard in the same channel where you have the long leg of the LED attached.
  4. Now connect one side of the 220 Ohm resistor to the short leg of the LED, and connect the other leg to the ground rail on the breadboard. The orientation of the resistor doesn’t matter.
  5. Repeat this using pin 12, and another LED and resistor.
  6. Finally, place your push button on the breadboard. Depending on the style of your pushbutton, they often fit well straddling the long trench that goes through the breadboard.
  7. Connect a jumper wire from one side of the button to pin 2 on the Arduino.
  8. Connect a jumper wire from the other side of the button to the ground rail on the breadboard.

That’s all for the circuit setup. Now, when you press the push button, pin 2 to will have the ground voltage applied. We will use this ground voltage input to trigger our different functions. This is how you change multiple pins using single button

Gurudarshan, I think there is some confusion. The question was regarding the singleButton Javascript function mentioned in the Bolt documentation.

Hi @sagarkamat,

Yes you can do that. Use the below example:

singleButton({name:"Led On", action:"digitalMultiWrite", 
              pins:[4,1,2], values:["HIGH","LOW","HIGH"]})

Also, check this API documentation https://docs.boltiot.com/docs/write-digital-output-1

Do let me know in case you need further assistance.

Thanks @rahul.singh1, that worked! One follow up question. Any idea why this is working for me with single button but not with dual button? In my code below, the LEFT and RIGHT singleButtons work as intended bu the exact same code inside the dual buttons isn’t.

singleButton({ name : "FORWARD", action :"digitalMultiWrite", pins:[1,2], values :["HIGH","HIGH"]});
singleButton({ name : "STOP", action :"digitalMultiWrite", pins:[1,2], values :["LOW","LOW"]});
singleButton({ name : "LEFT", action :"digitalMultiWrite", pins:[1,2], values :["HIGH","LOW"]});
singleButton({ name : "RIGHT", action :"digitalMultiWrite", pins:[1,2], values :["LOW","HIGH"]});

var dual = dualButton();
dual.first_button({ name : "LEFT", action :"digitalMultiWrite", pins:[1,2], values :["HIGH","LOW"]});
dual.second_button({ name : "RIGHT", action :"digitalMultiWrite", pins:[1,2], values :["LOW","HIGH"]});

Hi @sagarkamat,

I am checking it with the team and will update you by tomorrow EOD.

Do let me know in case you need further assistance.

1 Like