My track is finished ! Not yet :-(

Hi all,

I have finished the track with sensors, timers but now i have a problem with the code ! "yes!" :0

If u can help me please, but if you don't understand what does it mean, tell me please !

const int APPUI=1; 
const int PAS_APPUI=0; 

const int BEGIN=A1; // sensor 1
const int END=A4; // sensor 2

double timedebut = 0.0;
double timefin = 0.0;
double time;
double FPS = 0.3078 ;
double distance = 0.005;
double vitesse;
float Joules;
float FPS1;

int ETAT_BEGIN;
int ETAT_END;

void setup() {
  
Serial.begin(9600);
  
pinMode(BEGIN, INPUT);
pinMode(END, INPUT);

Serial.print("Okay");

}

void loop() {
  
do {  
  
  ETAT_BP1=digitalRead(BEGIN);
}

while(ETAT_BP1 == PAS_APPUI);

timedebut=micros();


do {
  
ETAT_BP2=digitalRead(END);

}
while (ETAT_BP2 == PAS_APPUI);
  
  timefin=micros();
 
  delay(1);

  time = (timefin - timedebut);
  vitesse = (distance/(time*0.000001))*10;
 
  FPS1 = vitesse / FPS;
  Joules = 0.5*sq(vitesse)*0.2*0.001;
  Serial.print(FPS1);
  Serial.print("\n");

}

micros does not return a double.
Why bother reading a time value 1000 microseconds after your end event?

Yes but it doesn't the big problem, i don't understand what's it :zipper_mouth_face:

Well, you haven't said what the "big problem" is

i choose micro because it's airsoft gun, the average output of barrel is 100 m/s or 325 FPS

In the Serial, the code returns :

Okay-6.63
40610.78
40610.78
40610.78
20305.39
40610.78
40610.78
40610.78
40610.78
40610.78
20305.39
20305.39
20305.39
20305.39
20305.39
20305.39
40610.78
20305.39
20305.39
20305.39
20305.39
40610.78
40610.78
40610.78
20305.39
20305.39
40610.78
40610.78
40610.78
40610.78
40610.78
20305.39
20305.39
40610.78
40610.78
40610.78
20305.39
20305.39
20305.39
20305.39
40610.78
40610.78
40610.78
40610.78
40610.78
20305.39
20305.39
40610.78
20305.39
20305.39
20305.39
20305.39
20305.39
20305.39
40610.78
20305.39
20305.39
20305.39
40610.78
20305.39
20305.39
20305.39
20305.39
20305.39
20305.39
20305.39
20305.39
20305.39
20305.39
20305.39
20305.39
20305.39
20305.39
20305.39
20305.39
20305.39

Can't see any debug output.

I know I find it : i have put the vitesse *10 and after / by a number < 1 so it was 10² more

I try it

Thanks you :slight_smile: