debuging

This program should time wheel rotation to give speed and duration of coasting and calculate deceleration.
can someone tell why it won’t progress past rotation 1? I am not sure if I am using long unsigned properly.
At first it checks for speed above the starting speed and buzzes for 1 second and checks for the specified beginning speed as the coast begins. Then it counts 100 wheel revolutions and measures the end speed and calculates deceleration, and starts another test. I have an adjustable oscillator with a optical pnp output and it works the rotation part OK. my first sketch hung up on the first speed test too.

sketch_ap11a.ino (2.68 KB)

while (test == 100) break;

That's a pretty useless line. If test is not 100 it fails right off and does nothing. If test IS 100 then it breaks the while loop and still does nothing.

Serial.println (rotate);Serial.println (x[rotate]);

Most of the time, rotate is larger than 5, so x[rotate] will be beyond the end of the x array.

test = +test;

What's that?

x[3] = 0;

Why are you setting x[3] back to zero at every iteration of loop? Don't you need that number later for your calculation?

I wanted to limit the tests maybe "if" is better than while.

The serial.print are there for debugging.

x[rotate] is only for 0,1 and 2. 96 is subtracted from the larger ones.

dexterj:
x[rotate] is only for 0,1 and 2. 96 is subtracted from the larger ones.

It is when you put the numbers in the array, but not when you call the print.

The test is the number of times the sketch can run.

After the deceleration is calculated the test starts new. x[3] is used to check if the speed checks have passed.

dexterj:
The test is the number of times the sketch can run.

After the deceleration is calculated the test starts new. x[3] is used to check if the speed checks have passed.

Nope, x[3] gets set to zero on every iteration of the loop. Look at where you put that line. So by the time you fill in x[4] you've lost x[3].

I think you may have some confusion about how the code runs. That loop function just keeps repeating itself. You're not doing the whole shebang in one run of loop. Loop will have run millions of times over by the time you've counted 100 revolutions.

yes Delta_G you are right I just need to remove the print, it was just there to see if it would get past rotation 2.

You are right again the curly bracket needs to be at the end.

Now the"if, break" doesn't work

dexterj:
Now the"if, break" doesn't work

if break? What are you thinking the break will do? It is only for breaking out of for loops and while loops. You have neither in your code.