# Right functions order in Arduino program using tilt sensor

I have the following problem using tilt sensor in my Arduino program. Without tilt sensor everything works correct, but during using tilt sensor the functions works not in the right order.

Hier first my version without tilt sensor. This version works fine. I' am using 710 leds in 5 lines. I have 4 functions, which starts one after another. The same principle i want to have using the tilt sensor. If i change the tilt position the program must start from another side of my light panel, like in hourglass.

Hier the link to stackoverflow: http://stackoverflow.com/questions/30453741/right-functions-order-in-arduino-program-using-tilt-sensor

If i use only 2 functions colorWipe and colorWipe3 (they starts from different sides of light panel) it works fine, but if i add colorWipe1 after colorWipe, i have the following mistake: colorWipe and colorWipe1 starts together, however without tilt each function starts after the previous function.

Thanks Andy

``````  for (k=1+b,l=282-b,m=283+b,n=566-b,o=567+b ;k<11+b,l<273-b,m<292+b, n<557-b, o<576+b; k=k+random(0,2),l=l-random(0,2),m=m+random(0,2),n=n-random(0,2),o=o+random(0,2)) {
``````

This is rubbish. The middle clause of a for loop defines what causes the loop to continue. You are sorely abusing the comma operator here.

Get all that initialization crap done BEFORE the for loop. The for loop should be concerned ONLY about the value of k.

Perhaps you meant:

``````  for (k=1+b,l=282-b,m=283+b,n=566-b,o=567+b ;
k<11+b && l<273-b && m<292+b && n<557-b && o<576+b ;  // ALL Conditions Must Be True
k=k+random(0,2),l=l-random(0,2),m=m+random(0,2),n=n-random(0,2),o=o+random(0,2)) {
``````

i’ll try this example with &&.
In my first example, without tilt sensor everything works property.
But if i try to use tilt sensor, i have the situation that two functions starts together (in my case colorWipe, colorWipe1)

Best regards
Anndy

I tried following:
" for (k=1+b,l=282-b,m=283+b,n=566-b,o=567+b ;
k<11+b && l<273-b && m<292+b && n<557-b && o<576+b ; // ALL Conditions Must Be True
k=k+random(0,2),l=l-random(0,2),m=m+random(0,2),n=n-random(0,2),o=o+random(0,2))"

In this case it does’t work

Andrey

anbuki:
I tried following:
" for (k=1+b,l=282-b,m=283+b,n=566-b,o=567+b ;
k<11+b && l<273-b && m<292+b && n<557-b && o<576+b ; // ALL Conditions Must Be True
k=k+random(0,2),l=l-random(0,2),m=m+random(0,2),n=n-random(0,2),o=o+random(0,2))"

I echo what @PaulS has said.

Write simple code that you can easily understand and debug.

…R