# How can I make a specific button run a specific loop?

**URL:** <https://forum.arduino.cc/t/how-can-i-make-a-specific-button-run-a-specific-loop/1172540>\
**Category:** LEDs and Multiplexing\
**Created:** [September 27, 2023, 2:08am UTC](https://forum.arduino.cc/t/how-can-i-make-a-specific-button-run-a-specific-loop/1172540 "2023-09-27T02:08:42Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![edrillz](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/edrillz/32/1003438_2.png) [@edrillz](https://forum.arduino.cc/u/edrillz)\
**Post date:** [September 27, 2023, 5:32pm UTC](https://forum.arduino.cc/t/how-can-i-make-a-specific-button-run-a-specific-loop/1172540/21 "2023-09-27T17:32:18Z")

</div>

Well you have to understand im not doing this for school or for work or anything im just trrying to figure this out i didnt mean to hurt your feelings or anything i just didnt care if i learned how to put a button in this in my opinion, like i wont ever use code again after this so it doesnt make sense for me to learn plus im trying to get this done asap cause its for my car so wether i learn or not i just wann try and get it working, its for my car and i have to drive 5 hrs in 2 days so its kinda important

---

<div class="post-metadata">

**Author:** ![paulpaulson](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paulpaulson/32/363643_2.png) [@paulpaulson](https://forum.arduino.cc/u/paulpaulson)\
**Post date:** [September 27, 2023, 5:35pm UTC](https://forum.arduino.cc/t/how-can-i-make-a-specific-button-run-a-specific-loop/1172540/22 "2023-09-27T17:35:57Z")

</div>

You can drop your request for a programmming service here:

> **[Jobs and Paid Consultancy](https://forum.arduino.cc/c/community/jobs/42)**
>
> Are you making a project and need people to help out? Calls for projects for exhibitions or faires.

---

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [September 27, 2023, 5:37pm UTC](https://forum.arduino.cc/t/how-can-i-make-a-specific-button-run-a-specific-loop/1172540/23 "2023-09-27T17:37:00Z")

</div>

> [@edrillz](#):
>
> i dont really care if i learn

This forum is for those that want to learn. What you want to do is not difficult.

Maybe if you wait long enough someone will write the code for you, but it won't be me.

Move your post to [the Jobs and Paid Consultancy category](https://forum.arduino.cc/c/community/jobs/42) where members that code for money can help you.

---

<div class="post-metadata">

**Author:** ![edrillz](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/edrillz/32/1003438_2.png) [@edrillz](https://forum.arduino.cc/u/edrillz)\
**Post date:** [September 27, 2023, 5:37pm UTC](https://forum.arduino.cc/t/how-can-i-make-a-specific-button-run-a-specific-loop/1172540/24 "2023-09-27T17:37:22Z")

</div>

so im nott getting help from yall?

---

<div class="post-metadata">

**Author:** ![edrillz](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/edrillz/32/1003438_2.png) [@edrillz](https://forum.arduino.cc/u/edrillz)\
**Post date:** [September 27, 2023, 5:38pm UTC](https://forum.arduino.cc/t/how-can-i-make-a-specific-button-run-a-specific-loop/1172540/25 "2023-09-27T17:38:56Z")

</div>

listen im not asking foranyone to make the code for me i just need help thats it

---

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [September 27, 2023, 5:55pm UTC](https://forum.arduino.cc/t/how-can-i-make-a-specific-button-run-a-specific-loop/1172540/26 "2023-09-27T17:55:42Z")

</div>

OK.

What Arduino do you have?

> [@edrillz](#):
>
> ```arduino
> #define BUTTON_PIN A5
> #define BUTTON_PIN A6
> #define BUTTON_PIN A7
> 
> ```

You have buttons attached to 3 pins but they all have the same name.

If you are using a classic Nano that actually has A6 and A7, those pins are analog input only. They have no digital functions. You can use them with button switched, but you can't use digitalRead() to read them. If you are using an Uno there are no A6 or A7 pins.

The most accepted way to wire switches is to wire one terminal of the switch to an input pin and, in setup(), set to pinMode to INPUT\_PULLUP and connect the other terminal to ground. The switch will read HIGH when not pressed and LOW when pressed.

 ![dig in no pullup](https://europe1.discourse-cdn.com/arduino/original/4X/9/b/1/9b114d4dfe023af8086484764710c67eb1773b8a.jpeg)

 ![dig sw button](https://europe1.discourse-cdn.com/arduino/original/4X/1/b/2/1b2f2806f40728ccf5e3f94516a645ac0aea533d.jpeg)

```arduino
void loop() {
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
}

```

That code is not in a function. In loop it will just run over and over so the LEDs will turn on and stay on. Nowhere do you attempt to read the states of the button switches.

All of the code after loop() is outside of any function and will not compile.

You did post the code in a code block, good job on that, thanks.

---

<div class="post-metadata">

**Author:** ![edrillz](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/edrillz/32/1003438_2.png) [@edrillz](https://forum.arduino.cc/u/edrillz)\
**Post date:** [September 27, 2023, 5:59pm UTC](https://forum.arduino.cc/t/how-can-i-make-a-specific-button-run-a-specific-loop/1172540/27 "2023-09-27T17:59:35Z")

</div>

i have a nano just a regular one, so ill go and change the analog outputs to a differnt connector, so to make a function what would i have to start doing

---

<div class="post-metadata">

**Author:** ![StefanL38](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/stefanl38/32/713548_2.png) [@StefanL38](https://forum.arduino.cc/u/StefanL38)\
**Post date:** [September 27, 2023, 6:09pm UTC](https://forum.arduino.cc/t/how-can-i-make-a-specific-button-run-a-specific-loop/1172540/28 "2023-09-27T18:09:00Z")

</div>

> [@edrillz](#):
>
> so to make a function what would i have to start doing

> **[Arduino Functions | How To Program and Use a Function](https://startingelectronics.org/software/arduino/learn-to-program-course/15-functions/)**
>
> Learn how to write and use functions with the Arduino in sketches. In this part of the programming course, functions are explained - calling a function, passing a value to and returning a value from a function.

---

<div class="post-metadata">

**Author:** ![StefanL38](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/stefanl38/32/713548_2.png) [@StefanL38](https://forum.arduino.cc/u/StefanL38)\
**Post date:** [September 27, 2023, 6:12pm UTC](https://forum.arduino.cc/t/how-can-i-make-a-specific-button-run-a-specific-loop/1172540/30 "2023-09-27T18:12:29Z")

</div>

@xfpd

you try to make a newcomer that has zero c++-knowledge to understand a program that uses interrupts and multiple functions without presenting the functions.

It is very **very**  **very** unlikely that this is understandable at a knowledge-level of almost zero

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [September 27, 2023, 6:14pm UTC](https://forum.arduino.cc/t/how-can-i-make-a-specific-button-run-a-specific-loop/1172540/31 "2023-09-27T18:14:17Z")

</div>

I see. Redacted.

---

<div class="post-metadata">

**Author:** ![StefanL38](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/stefanl38/32/713548_2.png) [@StefanL38](https://forum.arduino.cc/u/StefanL38)\
**Post date:** [September 27, 2023, 6:18pm UTC](https://forum.arduino.cc/t/how-can-i-make-a-specific-button-run-a-specific-loop/1172540/32 "2023-09-27T18:18:39Z")

</div>

> [@edrillz](#):
>
> listen im not asking foranyone to make the code for me i just need help thats it

there are several ways to "help" in this situation:

1. writing the code for you. (not just help but doing all the work

2. writing a personal tutorial just for you (a lot of effort nobody will take)

3. posting links where you can learn programming

the most effective help would be:  
4. posting your best attempt how to code it combined with **specific** questions asked by **you**

going on modifying your code with the given answers

and repeat this cycle until te code works as you want.

As an example for an specific question:

You wrote this:

> [@edrillz](#):
>
> Ive been going at this for a while and i cant seem to put a function in bout to give up lol

This is just a statement. The most important thing is to post your modified code.  
If you post your modified code it will be possible to **help** you by explaining what to change in the code.

Another idea:  
buy two additional arduino nanos  
and connect not momentary push-buttons but a three position rotary-switch where each contact will give power to one of the three arduino nanos and you are done.

There is a famous wording about projects:

projects can be cheap, quick, good - take two

best regards Stefan

---

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [September 27, 2023, 6:23pm UTC](https://forum.arduino.cc/t/how-can-i-make-a-specific-button-run-a-specific-loop/1172540/33 "2023-09-27T18:23:49Z")

</div>

> [@edrillz](#):
>
> to make a function what would i have to start doing

In post #3 i linked a tutorial on functions And in post #28 @StefanL38 linked a tutorial on functions. Try writing a function, post the code, ask questions and we can help fill in the blanks.

---

<div class="post-metadata">

**Author:** ![PerryBebbington](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/perrybebbington/32/238766_2.png) [@PerryBebbington](https://forum.arduino.cc/u/PerryBebbington)\
**Post date:** [September 27, 2023, 6:25pm UTC](https://forum.arduino.cc/t/how-can-i-make-a-specific-button-run-a-specific-loop/1172540/34 "2023-09-27T18:25:08Z")

</div>

@edrillz ,

Your other topic on the same subject deleted.

Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.

Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you take a few moments to Learn How To Use The Forum

> [@How to get the best out of this forum](https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966):
>
> See also [FAQ - Arduino Forum](https://forum.arduino.cc/faq) for general rules on forum behaviour and etiquette. Hello, Welcome to the Arduino Forum. This guide explains how to get the best out of this forum. Please read and follow the instructions below. Being new here you might think this is having rules for the sake of rules, but that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of posts while we try to get you to tell us what we need in order to help you, which is fru…

It will help you get the best out of the forum in the future.

Thank you.

---

<div class="post-metadata">

**Author:** ![2112](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/2112/32/1129664_2.png) [@2112](https://forum.arduino.cc/u/2112)\
**Post date:** [September 27, 2023, 6:38pm UTC](https://forum.arduino.cc/t/how-can-i-make-a-specific-button-run-a-specific-loop/1172540/35 "2023-09-27T18:38:34Z")

</div>

> [@edrillz](#):
>
> will make the LEDS solid and lit up,

Are these 5 single LEDs or 5 LED strips?  
You will need additional hardware if they are LED strips.

There are additional hardware considerations if you are using the automobile power system to power this project.

I do not believe A6 and A7 have internal pull up resistors for button switches. Consider using digital pins for this.

---

<div class="post-metadata">

**Author:** ![StefanL38](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/stefanl38/32/713548_2.png) [@StefanL38](https://forum.arduino.cc/u/StefanL38)\
**Post date:** [September 27, 2023, 6:39pm UTC](https://forum.arduino.cc/t/how-can-i-make-a-specific-button-run-a-specific-loop/1172540/36 "2023-09-27T18:39:40Z")

</div>

> [@edrillz](#):
>
> so to make a function what would i have to start doing

explanation:  
opening curly brace is this "{"  
closing curly brace is this "}"

write a function-defintion.

```arduino
void name_of_the-function() 
{
// put the code that you have inside function loop() between the opening and the closing curly braces
}

```

do this for each of the three functions "loop()"  
for each function use a different name.

---

<div class="post-metadata">

**Author:** ![edrillz](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/edrillz/32/1003438_2.png) [@edrillz](https://forum.arduino.cc/u/edrillz)\
**Post date:** [September 27, 2023, 6:42pm UTC](https://forum.arduino.cc/t/how-can-i-make-a-specific-button-run-a-specific-loop/1172540/37 "2023-09-27T18:42:19Z")

</div>

single leds

---

<div class="post-metadata">

**Author:** ![StefanL38](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/stefanl38/32/713548_2.png) [@StefanL38](https://forum.arduino.cc/u/StefanL38)\
**Post date:** [September 27, 2023, 6:50pm UTC](https://forum.arduino.cc/t/how-can-i-make-a-specific-button-run-a-specific-loop/1172540/38 "2023-09-27T18:50:51Z")

</div>

even if these are single leds.  
What current-limiting resistor are you using?

---

<div class="post-metadata">

**Author:** ![edrillz](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/edrillz/32/1003438_2.png) [@edrillz](https://forum.arduino.cc/u/edrillz)\
**Post date:** [September 27, 2023, 7:05pm UTC](https://forum.arduino.cc/t/how-can-i-make-a-specific-button-run-a-specific-loop/1172540/39 "2023-09-27T19:05:53Z")

</div>

im not to sure unforutanly

---

<div class="post-metadata">

**Author:** ![gilshultz](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gilshultz](https://forum.arduino.cc/u/gilshultz)\
**Post date:** [September 27, 2023, 7:20pm UTC](https://forum.arduino.cc/t/how-can-i-make-a-specific-button-run-a-specific-loop/1172540/40 "2023-09-27T19:20:33Z")

</div>

Considering headlights are safety items on a car I am backing out, because of the potential liability if something goes wrong and somebody gets hurt or something gets damaged. Good luck!

---

<div class="post-metadata">

**Author:** ![StefanL38](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/stefanl38/32/713548_2.png) [@StefanL38](https://forum.arduino.cc/u/StefanL38)\
**Post date:** [September 27, 2023, 7:25pm UTC](https://forum.arduino.cc/t/how-can-i-make-a-specific-button-run-a-specific-loop/1172540/41 "2023-09-27T19:25:11Z")

</div>

> [@edrillz](#):
>
> This isn’t a school project it’s a personal project I’m making for a car headlight

so what kind of LEDs are this?  
car headlight sounds like that these LEDs have to have much more brightness than such an LED with a diameter of 5 mm = 0.2 inch  
 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/1/5/0/1501e15b1c4f4509fb8befd1913ba853609d89f4.png)

[Previous page](https://forum.arduino.cc/t/how-can-i-make-a-specific-button-run-a-specific-loop/1172540.md?page=1)

[Next page](https://forum.arduino.cc/t/how-can-i-make-a-specific-button-run-a-specific-loop/1172540.md?page=3)
