so im working on the same ASKmanual right now from eartshinedesign wich is now offline because he is working on a complete book.
anyhow the bouncing ball exercise.
just like the TS i came to the same conclusion for maken the light decade one led every time it hits 0 but it just doesnt work it keeps shifting to the 10 led.
Can someone pls help me find the problem.
here is the code.
void changeled()
{
for (byte x=0; x<10; x++)
{
digitalWrite(ledpin[x], LOW);
}
digitalWrite(ledpin[currentled], HIGH);
currentled += dir;if (currentled == bounce) // bounce is global variable set at 9 to start with
{
dir = -1;
bounce -= 1;
}
if (currentled == 0)
{
dir = 1;
}
if (bounce == 0)
{
bounce = 9;
}
}
so to be precise.
the led start ad led 10 than scrols back to led 0 when it hit zero bounce should be 8 so that it goes back up to led 9 an then back to zero when it hit zero again bounce has to become 8 so it scrols back to led 7 repeat this steps till it hits zero en the ball has no kinectic energy left. When 0 is reached bounce become 9 again and the process starts over and over and over again.
ok put bounce -= 1 under current == 0 instead of under currentled == bounce and now it works flawless ;D