Pages: 1 [2]   Go Down
Author Topic: Multiple Blink States with a button no delay  (Read 1250 times)
0 Members and 1 Guest are viewing this topic.
Malaysia
Offline Offline
Sr. Member
****
Karma: 7
Posts: 393
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 50243
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Malaysia
Offline Offline
Sr. Member
****
Karma: 7
Posts: 393
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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:
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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 50243
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: 1 [2]   Go Up
Jump to: