Help Needed for button/LED control!

Hi there,

I really hope someone has the time to help, as I have been given a live project to produce for a client and I am running out if time! I got so far with working all this out with my newbie skills and now some extra functionality has been added to the brief and now I am a bit lost.

A description of what is required;

6 separate buttons switch off a light associated to them only
when a button is pressed once, there is a 2 second delay and the button's associated light switches off and cannot be switched back on again by the button
15 seconds after any of the buttons pressed the whole system needs to return to the beginning with all lights back on. An idle reset.
Another separate set of 6 lights turn on in order indicating how many of the 1st set of lights are currently off.(as the first 6 buttons switch their light off in any possible order, the second set turn on IN order)

Hopefully this makes sense!

Here is what I have so far,

The buttons here still turn lights back on and I can work out a 15 second restart function.

Any help/advice is greatly appreciated!

const int buttonPin1  = 2;     // the pin that the pushbutton is attached to
const int ledPin1     = 13;    // the pin that the LED is attached to
int buttonState1      = 0;     // current state of the button
int lastButtonState1  = 0;     // previous state of the button
int ledState1         = 0;     // remember current led state

const int buttonPin2  = 3;     // the pin that the pushbutton is attached to
const int ledPin2    = 12;    // the pin that the LED is attached to
int buttonState2      = 0;     // current state of the button
int lastButtonState2  = 0;     // previous state of the button
int ledState2         = 0;     // remember current led state

const int buttonPin3  = 4;     // the pin that the pushbutton is attached to
const int ledPin3     = 11;    // the pin that the LED is attached to
int buttonState3      = 0;     // current state of the button
int lastButtonState3  = 0;     // previous state of the button
int ledState3         = 0;     // remember current led state

const int buttonPin4  = 5;     // the pin that the pushbutton is attached to
const int ledPin4     = 10;    // the pin that the LED is attached to
int buttonState4      = 0;     // current state of the button
int lastButtonState4  = 0;     // previous state of the button
int ledState4         = 0;     // remember current led state

const int buttonPin5  = 6;     // the pin that the pushbutton is attached to
const int ledPin5     = 9;    // the pin that the LED is attached to
int buttonState5      = 0;     // current state of the button
int lastButtonState5  = 0;     // previous state of the button
int ledState5         = 0;     // remember current led state

const int buttonPin6  = 7;     // the pin that the pushbutton is attached to
const int ledPin6     = 8;    // the pin that the LED is attached to
int buttonState6      = 0;     // current state of the button
int lastButtonState6  = 0;     // previous state of the button
int ledState6         = 0;     // remember current led state

int result            = 0;

int meterled1         = 22;
int meterled2         = 23;
int meterled3         = 24;
int meterled4         = 25;
int meterled5         = 26;
int meterled6         = 27;

void setup() {
  pinMode(buttonPin1, INPUT_PULLUP);  // initialize the button pin as a input
  pinMode(ledPin1, OUTPUT);    // initialize the button pin as a output
  
  pinMode(buttonPin2, INPUT_PULLUP);  // initialize the button pin as a input
  pinMode(ledPin2, OUTPUT); 
  
  pinMode(buttonPin3, INPUT_PULLUP);  // initialize the button pin as a input
  pinMode(ledPin3, OUTPUT); 
  
  pinMode(buttonPin4, INPUT_PULLUP);  // initialize the button pin as a input
  pinMode(ledPin4, OUTPUT); 
  
  pinMode(buttonPin5, INPUT_PULLUP);  // initialize the button pin as a input
  pinMode(ledPin5, OUTPUT); 
  
  pinMode(buttonPin6, INPUT_PULLUP);  // initialize the button pin as a input
  pinMode(ledPin6, OUTPUT); 
  
  pinMode(result, OUTPUT);
  
  pinMode(meterled1, OUTPUT);
  pinMode(meterled2, OUTPUT);
  pinMode(meterled3, OUTPUT);
  pinMode(meterled4, OUTPUT);
  pinMode(meterled5, OUTPUT);
  pinMode(meterled6, OUTPUT);
  }
void loop() {   
      buttonState1 = digitalRead(buttonPin1);
  if (buttonState1 != lastButtonState1) {
  if (buttonState1 == 1) {
  if(ledState1==1) ledState1=0;
  else ledState1=1;        
    }
   lastButtonState1 = buttonState1;
  }
  digitalWrite(ledPin1, ledState1);
        delay(20);

buttonState2 = digitalRead(buttonPin2);
  if (buttonState2 != lastButtonState2) {
  if (buttonState2 == 1) {
  if(ledState2==1) ledState2=0;
  else ledState2=1;        
    }
   lastButtonState2 = buttonState2;
  }
  digitalWrite(ledPin2, ledState2);
  delay(20);
  
 buttonState3 = digitalRead(buttonPin3);
  if (buttonState3 != lastButtonState3) {
  if (buttonState3 == 1) {
  if(ledState3==1) ledState3=0;
  else ledState3=1;        
    }
   lastButtonState3 = buttonState3;
  }
  digitalWrite(ledPin3, ledState3);
  delay(20);
  
  buttonState4 = digitalRead(buttonPin4);
  if (buttonState4 != lastButtonState4) {
  if (buttonState4 == 1) {
  if(ledState4==1) ledState4=0;
  else ledState4=1;        
    }
   lastButtonState4 = buttonState4;
  }
  digitalWrite(ledPin4, ledState4);
  delay(20);
  
  buttonState5 = digitalRead(buttonPin5);
  if (buttonState5 != lastButtonState5) {
  if (buttonState5 == 1) {
  if(ledState5==1) ledState5=0;
  else ledState5=1;        
    }
   lastButtonState5 = buttonState5;
  }
  digitalWrite(ledPin5, ledState5);
  delay(20);
  
  buttonState6 = digitalRead(buttonPin6);
  if (buttonState6 != lastButtonState6) {
  if (buttonState6 == 1) {
  if(ledState6==1) ledState6=0;
  else ledState6=1;        
    }
   lastButtonState6 = buttonState6;
  }
  digitalWrite(ledPin6, ledState6);
  delay(20);
  
  {result = ledState1 + ledState2 + ledState3 + ledState4 + ledState5 + ledState6;}
   
 {            
  if (result>=1)
  digitalWrite(meterled6, LOW);
  else 
  digitalWrite(meterled6, HIGH);
  
  if (result>=2)
  digitalWrite(meterled5, LOW);
  else 
  digitalWrite(meterled5, HIGH);
  
  if (result>=3)
  digitalWrite(meterled4, LOW);
  else 
  digitalWrite(meterled4, HIGH);
  
  if (result>=4)
  digitalWrite(meterled3, LOW);
  else 
  digitalWrite(meterled3, HIGH);
  
  if (result>=5)
  digitalWrite(meterled2, LOW);
  else 
  digitalWrite(meterled2, HIGH);
  
  if (result>=6)
  digitalWrite(meterled1, LOW);
  else 
  digitalWrite(meterled1, HIGH);
    
 }
    }

It sounds like from your specs. you will not be able to use delay(). Look at the example program "blink without delay", in the examples of the IDE.

Thanks for the advice,

I have worked on this more and a getting much closer now so i can ask some much more specific questions.

I am just having some issues with the using the millis function to turn everything back on after X amount of time. I think I have got everything correct, i just cant seem to find where the issue is.
The problems that occur are;
Everything works fine until the program time has exceeded my timeout limit (5*1000) then everything is constantly set to high and functionality is lost.
Each button needs pressing once the first time then twice the second time... really not sure how that could happen...

If you have any more advice it would be very much appreciated!

Thanks in advance,

const int  buttonPin1   = 2;   
const int ledPin1       = 13;       
int buttonPushCounter1   = 0;   
int buttonState1         = 0;         
int lastButtonState1     = 0; 
unsigned long buttonPushTime1 = 0;

const int  buttonPin2   = 3;   
const int ledPin2       = 12;       
int buttonPushCounter2   = 0;   
int buttonState2         = 0;         
int lastButtonState2     = 0; 
unsigned long buttonPushTime2 = 0;

int result                = 0;
int duration               = 0;

int meterled1             = 22;
int meterled2             = 23;

void setup() {
   pinMode(buttonPin1, INPUT_PULLUP);
   pinMode(ledPin1, OUTPUT);
   
   pinMode(buttonPin2, INPUT_PULLUP);
   pinMode(ledPin2, OUTPUT);
   
   pinMode(meterled1, OUTPUT);
   pinMode(meterled2, OUTPUT);
}
void loop() {
  
  buttonState1 = digitalRead(buttonPin1);
   if (buttonState1 != lastButtonState1) {
   if (buttonState1 == HIGH) {
   buttonPushCounter1++; 
   buttonPushTime1 = millis();
   }
   }
   lastButtonState1 = buttonState1;
  
    
  buttonState2 = digitalRead(buttonPin2);
   if (buttonState2 != lastButtonState2) {
   if (buttonState2 == HIGH) {
   buttonPushCounter2++; 
   buttonPushTime2 = millis();
   }
   }
   lastButtonState2 = buttonState2;
   
   {
   if (buttonPushCounter1 > 1) 
   digitalWrite(ledPin1, LOW);
   else 
   digitalWrite(ledPin1, HIGH);
   
   if (buttonPushCounter2 > 1) 
   digitalWrite(ledPin2, LOW);
   else 
   digitalWrite(ledPin2, HIGH);
   }
       
 {result = (digitalRead (ledPin1))+(digitalRead (ledPin2));}
 
 { if (result>=1)
  digitalWrite(meterled2, LOW);
  else 
  digitalWrite(meterled2, HIGH);}
  
  {if (result>=2)
  digitalWrite(meterled1, LOW);
  else 
  digitalWrite(meterled1, HIGH);}
  
  
 {duration = ((buttonPushTime1+buttonPushTime2)/2);}
     if (duration!=0) {
 unsigned long timeSincePush = millis()-duration;
    if (timeSincePush > (5*1000)) {
      buttonPushTime1 = 0;
      buttonPushTime2 = 0;
      digitalWrite(ledPin1, HIGH);
      digitalWrite(ledPin2, HIGH);
      buttonPushCounter1 = 0;
      buttonPushCounter2 = 0;
      }
    }
}