Go Down

### Topic: Multiple Blink States with a button no delay (Read 2690 times)previous topic - next topic

#### ash901226

#15
##### Feb 03, 2013, 04:33 pm
there have been many time that count become a runaway, haha but i had done a few if statement so that it will never go higher then 15. i have use the serial.println to see all the value of Count and it does go to 0. btw its not random that what happen to case 3, it happen in a perticular sequence that is not like i state in patern3

#### PaulS

#16
##### Feb 03, 2013, 04:37 pm
Some Serial.print() statements would go a long way towards understanding your issue (which I still don't). On any given pass through loop(), State has a value. What is it? Under what circumstances does it change? Do those circumstances happen correctly? Does State change appropriately?

On any given pass through loop(), Count starts with some value. What is it? Count changes. Does it change at the appropriate time? To the appropriate value?
The art of getting good answers lies in asking good questions.

#### ash901226

#17
##### Feb 03, 2013, 04:45 pm
Pauls,
I have verify that State value will be updated everytime i press the Switch,
i also have verify that count will start at 0 and every 500millisecond it will increase by 1
i also verify that if State value change, count will reset. what i dont get is this one
Code: [Select]
`int State2[4][2]=    {      (0,1),      (1,1),      (0,0),      (1,0),    };int State3[8][3]=    {      (0,0,0),      (0,0,1),      (0,1,0),      (0,1,1),      (1,0,0),      (1,0,1),      (1,1,0),      (1,1,1),    };`

and this one
Code: [Select]
`case(2):        digitalWrite(Led[0],State2[Count][0]);    digitalWrite(Led[1],State2[Count][1]);    if (Count==6)Count=0;    break;    case(3):        digitalWrite(Led[0],State3[Count][0]);    digitalWrite(Led[1],State3[Count][1]);    digitalWrite(Led[2],State3[Count][2]);    if (Count==9)Count=0;    break;`

as you can see that in case2 i have use the pattern in State2, however what i dont get why do i need to reset Count==6 as oppose to 4/5?
and in case 3
i use the pattern that i set in State3, however what i dont get is although it doesnt follow the pattern that i have set in array State3, it does however able to repeat the same sequence every time though its not the one that i have set, i can also verify that all my led work and pin work

#### PaulS

#18
##### Feb 03, 2013, 04:53 pm
Quote
as you can see that in case2 i have use the pattern in State2, however what i dont get why do i need to reset Count==6 as oppose to 4/5?

I don't either. Why do you think you need to? It looks to me like when the value gets to 3, it should be reset to 0, since 3 is the highest valid index into State2.

In case 3, Count should be reset when it gets to 7, since that is the highest valid index into State3.

Of course, using int as the type for those arrays is a waste of space.

Serial.print() the array (one element at a time) to see if something is stepping on the array.
The art of getting good answers lies in asking good questions.

Go Up