I have written a little project, it works so far as it should but the for loop is only iterated once, then the result is displayed on the LCD.
#include <LiquidCrystal.h>
#include <stdlib.h>
const int Contrast=20;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int led = A5;
const int button = A3;
void setup() {
Serial.begin(9600);
analogWrite(6,Contrast);
lcd.begin(16, 2);
pinMode(led, OUTPUT);
digitalWrite(led,LOW);
pinMode(button, INPUT_PULLUP);
}
void loop() {
unsigned long mittelwert = 0;
for(int i=0; i<10; i++){
unsigned long r = random(1,5000);
unsigned long now = millis();
digitalWrite(led,HIGH);
while (digitalRead(button) == HIGH){
lcd.setCursor(0,0);
lcd.print("druecken");
}
mittelwert = mittelwert + millis() - now;
digitalWrite(led, LOW); //LED aus
}
lcd.clear();
lcd.setCursor(0,0); //setze Cursor auf 1.Stelle in der 1. Zeile
lcd.print(mittelwert/1000);
lcd.setCursor(0,1);
lcd.print("Sekunden");
delay(5000);
lcd.clear();
}