Beginner question

Hello everybody,
I tried some basic stuff with arduino, and I wonder how long the led2 flashes after the button is pushed, it seems like extremely short time, but I don't know exactly how long it is?

Here is the code:

const int buttonPin = 2;
const int led2 = 13;
const int led1 = 10;

int buttonState = 0;

void setup() {

pinMode(led2, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(buttonPin, INPUT);
}

void loop(){

buttonState = digitalRead(buttonPin);

if (buttonState == HIGH) {

digitalWrite(led1, HIGH);
delay(1000);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);

}
else {

digitalWrite(led2, LOW);
}
}

Typo here:

pinMode(led2, OUTPUT);  
  pinMode(led2, OUTPUT);

One of them should presumably be led1.

Led2 will stay on while the button is pressed by the look of it - not a specific time. You'll probably be getting some contact bounce too, but it's not likely to be human visible.

with that code, led2 is only on as long as you press the button.
(as well as taking into consideration the blocking of 1000 milliseconds used on led1)

try the code with just led2 to see what is happening.

and don't forget to use the CODE tags -->

yes, the 1. output is led1 , when I tried with only led 2, then the led 2 glows exactly the same time the button is pushed, but with led 1 and 2 it glows for extremely short time independently on the time I hold the button. Is there any way I can measure that time?

Is there any way I can measure that time?

Look at the millis timer in the programming reference.

Thx for the timer, I put the timer after the led 2 and the problem is that it's time constantly increases. When I push the button, then it shows the time in serial monitor. What can I change to get only the led 2 flashing time ?

unsigned long time;

const int buttonPin = 2;     
const int led2 =  13;      
const int led1 =  10;

int buttonState = 0;         

void setup() {
  Serial.begin(9600);
  
  pinMode(led2, OUTPUT);  
  pinMode(led2, OUTPUT);
  pinMode(buttonPin, INPUT);     
}

void loop(){
  
  buttonState = digitalRead(buttonPin);


  if (buttonState == HIGH) {       

    digitalWrite(led1, HIGH);
    delay(1000);
    digitalWrite(led1, LOW); 
    digitalWrite(led2, HIGH);
    time = millis();
    Serial.println(time);
    
   
  } 
  else {
 

    digitalWrite(led2, LOW); 
  }
}

millis() returns the number of milliseconds since the program started. If you store it once, you can compare to that stored value to calculate time elapsed.