button condition high for 20 second

Someone can help me .. i want the condition of button 'high' for 20 second after i presssed the button once .

// set pin numbers:
int button = A3;
int button2 = A2;
int button3 = A1;
int button4 = A0;
int button5 = 13;
int button6 = 12;
int button7 = 11; // the number of the pushbutton pin

int valbutton = 0;
int valbutton2 = 0;
int valbutton3 = 0;
int valbutton4 = 0;
int valbutton5 = 0;
int valbutton6 = 0;
int valbutton7 = 0;

const int ledPin = 10; // the number of the LED pin

// variables will change:
int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(button, INPUT);
pinMode(button2, INPUT);
pinMode(button3, INPUT);
pinMode(button4, INPUT);
pinMode(button5, INPUT);
pinMode(button6, INPUT);
pinMode(button7, INPUT);
}

void loop() {
// read the state of the pushbutton value:
valbutton = digitalRead(button);
valbutton2 = digitalRead(button2);
valbutton3 = digitalRead(button3);
valbutton4 = digitalRead(button4);
valbutton5 = digitalRead(button5);
valbutton6 = digitalRead(button6);
valbutton7 = digitalRead(button7);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:

if (valbutton == 1 ) {

{

digitalWrite(ledPin, HIGH);
}
}
if (valbutton2 == 1)
{
// turn LED on:
digitalWrite(ledPin, HIGH);
}

if (valbutton == 0 && valbutton2 == 0 && valbutton3 == 0 && valbutton4 == 0 && valbutton5 == 0 && valbutton6 == 0 && valbutton7 == 0)//stop command

{
// turn LED off:
digitalWrite(ledPin, LOW);
}
}

Use millis() to save the time the button became pressed. After which you can check the current time (again, millis()) and the current button state to trigger something.

Have a look at

  • How to use the forum
  • Blink without delay
  • State change example

And a tip, if you start numbering variables, arrays is the answer :wink: