Hi guys, I've built a circuit where I press two buttons at a certain interval. I want to measure the time interval. But it doesn't work for me and I get wrong values. Can someone tell me what I'm doing wrong and help me?
here my circuit: Circuit design Cool Curcan | Tinkercad
here my code:
int buttonState1 = 0;
int buttonState2 = 0;
unsigned int long start;
unsigned int long ende;
unsigned int long dauer;
int condition = 0;
void setup()
{
pinMode(2, INPUT);
pinMode(13, OUTPUT);
pinMode(3, INPUT);
pinMode(12, OUTPUT);
Serial.begin(9600);
Serial.println("Zeit");
}
void loop()
{
while(digitalRead(2)==condition){
start = millis();}
while(digitalRead(3)==condition){
ende=millis();
dauer = ende - start;}
Serial.println(dauer);
}