#define LDR1 32
#define LDR2 33

unsigned long startTime = 0; // benyttes til at gemme meget store tal se mere i Arduino referencemanual
unsigned long endTime = 0;
unsigned long duration =0 ;
bool timerRunning = false;
int n;

void setup(){
pinMode (LDR1, INPUT);
pinMode (LDR2, INPUT);
Serial.begin(115200); // start serial monitor. 
}
void loop(){
  if (timerRunning == false && digitalRead(LDR1) == HIGH && digitalRead(LDR2) == LOW) { // bold foran LDR1 && betyder AND 
  startTime = millis();// millis(s) giver tiden i ms siden arduinoen startede. Derfor hurtigt et stort tal.
  timerRunning = true;
  }
  if (timerRunning == true && digitalRead(LDR1) == LOW && digitalRead(LDR2) == HIGH) { // bold foran LDR2
  endTime = millis();
  timerRunning = false;
  duration = endTime - startTime;
  Serial.print ("laser press time in milliseconds: ");
  Serial.println (duration);
  }
  n =n+1;
  Serial.println("--------------------------------------");
  Serial.print("Gennemløb nr.");
  Serial.println(n);
  Serial.print("kører timer ?:");
  Serial.println(timerRunning);
  Serial.print("LDR1:");
  Serial.println(digitalRead(LDR1));
  Serial.print("LDR2:");
  Serial.println(digitalRead(LDR2));
  Serial.print("Skuddets varighed: ");
  Serial.println(duration);
  delay(1000);
}