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

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

You can drop your request for a programmming service here:

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 where members that code for money can help you.

1 Like

so im nott getting help from yall?

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

OK.

What Arduino do you have?

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.

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.

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

@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

1 Like

I see. Redacted.

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:

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

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.

@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

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

Thank you.

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.

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

write a function-defintion.

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.

single leds

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

im not to sure unforutanly

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!

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