Hi, yes, this works but.... that I need, is the sequence starts without release button.... in your example need to release button and I need at 30 seconds of pushed button start sequence, until push button still pushed.
silly_cone:
I think I see the problem. The button pin was set to INPUT_PULLUP which means it always reads HIGH. So the code was going straight into the while-loop and getting stuck there.
When you set a button pin to INPUT_PULLUP, you actually need to look for the button going LOW to indicate a press. I fixed that in the code below. It listens for the button being pulled low, then starts a timer that increments while the button is being held down. When the button is released, it checks how long it was pressed, and if longer than the given threshold, it goes into the LED portion of the code.
const int buttonPin = 10, rows = 8, cols = 2;
const int output[rows][cols] =
{
{2, 10000},
{3, 20000},
{4, 15000},
{5, 10000},
{6, 12000},
{7, 18000},
{8, 9000},
{9, 5000}
};
int buttonstate1;
void setup() {
for (int i=0; i<rows; i++){
pinMode(output[i][0], OUTPUT);
}
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
if(digitalRead(buttonPin)==0) {
unsigned long tic = millis();
unsigned long toc;
while(digitalRead(buttonPin)==0) {
toc = millis() - tic;
}
if(toc > 30000){
for (int i=0; i<rows; i++){
digitalWrite(output[i][0], HIGH);
delay(output[i][1]);
digitalWrite(output[i][0], LOW);
}
delay(100);
}
}
}