Hi, i'm new to arduino i wanted to combine two codes sequential blinking and one pushbutton that make of and on the LEDs but for me it is not working can anyone combine for me please also if there is much easier way to do i will apreciate it
this one if for the button,
const int button = 6; //button pin, touch to ground as button
const int ledPin = 10;
int buttonState = 0;
boolean toggle = true;
void setup()
{
pinMode(ledPin, OUTPUT); //LED on pin 13
pinMode(button, INPUT); //arduino monitor pin state
digitalWrite(button, HIGH); //enable pullups to make pin 5 high
}
void loop()
{
buttonState = digitalRead(button);
if (buttonState == LOW)
{
if(toggle)
{
digitalWrite(ledPin, HIGH); // set the LED on
toggle = !toggle;
}
else
{
digitalWrite(ledPin, LOW); // set the LED off
toggle = !toggle;
}
}
delay(200); //delay for debounce
}
int timer = 500; // The higher the number, the slower the timing.
int ledPins[] = {
7, 6, 5,4, 3,2
}; // an array of pin numbers to which LEDs are attached
int pinCount = 6; // the number of pins (i.e. the length of the array)
void setup() {
// the array elements are numbered from 0 to (pinCount - 1).
// use a for loop to initialize each pin as an output:
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
pinMode(ledPins[thisPin], OUTPUT);
}
}
void loop() {
// loop from the lowest pin to the highest:
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
// turn the pin on:
digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
// turn the pin off:
digitalWrite(ledPins[thisPin], LOW);
}
// loop from the highest pin to the lowest:
for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) {
// turn the pin on:
digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
// turn the pin off:
digitalWrite(ledPins[thisPin], LOW);
}
}