Hi my code currently is not completely working the way i want i'm kinda new to arduino right now all my lamps act correctly the way i want but when i want to press the button i want all leds to stop flickering and only the green one to turn on for 3 seconds and than turn off after that i want the loop to continue again unless i press the button any idea's? this is my code
const int buttonPin = 7;
const int ledGroen = 4;
int buttonState = 0;
int ledpins[5]={2,3,4,5,6};
To set the pinMode of your leds as well as turn them off/on, you need to access each member of the array individually
void setup() {
pinMode(buttonPin, INPUT);
pinMode(ledGroen, OUTPUT);
for (int i = 0; i < 5; i++) {
pinMode(ledpins[i], OUTPUT);
}
}
The same is true for accessing them in your loop() function, but I'll let you figure that out.
How do you have your button wired up? Does it have a pull-down resistor attached? Your code will require one to be present to prevent your button pin from "floating" which can give you either HIGH or LOW on any given moment. A better way would be to wire one side of your button to ground, the other to your pin and then set the mode to INPUT_PULLUP which keeps the button HIGH when not pressed and then LOW when you press it and connect it to ground.