rite now i have this sketch
void loop()
{
switch (state1)
{
case 1:
digitalWrite (pinLED[0],HIGH);
Timer[0]=millis();
state1=2;
break;
case 2:
if ( millis() - Timer[0] >= TimerON[0])
{
state1=3;
}
break;
case 3:
digitalWrite (pinLED[0],LOW);
Timer[0]=millis();
state1=4;
break;
case 4:
if ( millis() - Timer[0] >= TimerOFF[0])
{
Count1--;
if (Count1>0){state1=1;}
else {state1=5;}
}
break;
case 5:
digitalWrite (pinLED[0],LOW);
break;
default:
state1=1;
break;
}
switch (state2)
{
case 1:
digitalWrite (pinLED[1],HIGH);
Timer[1]=millis();
state2=2;
break;
case 2:
if ( millis() - Timer[1] >= TimerON[1])
{
state2=3;
}
break;
case 3:
digitalWrite (pinLED[1],LOW);
Timer[1]=millis();
state2=4;
break;
case 4:
if ( millis() - Timer[1] >= TimerOFF[1])
{
Count2--;
if (Count2>0){state2=1;}
else {state2=5;}
}
break;
case 5:
digitalWrite (pinLED[1],LOW);
break;
default:
state2=1;
break;
}
}
what it does is it actually a blink without delay using Finite State machine. I know maybe useless but it does make me understand the 2 concept better. anyway i have come to a point where i want to use this code to control a stepper controller that need only step/dir logic only. the problem is how could i make this into a function that could be easily call up like maybe
step(pin number,number of step) whereby the function is only
switch (state1)
{
case 1:
digitalWrite (pinLED[0],HIGH);
Timer[0]=millis();
state1=2;
break;
case 2:
if ( millis() - Timer[0] >= TimerON[0])
{
state1=3;
}
break;
case 3:
digitalWrite (pinLED[0],LOW);
Timer[0]=millis();
state1=4;
break;
case 4:
if ( millis() - Timer[0] >= TimerOFF[0])
{
Count1--;
if (Count1>0){state1=1;}
else {state1=5;}
}
break;
case 5:
digitalWrite (pinLED[0],LOW);
break;
default:
state1=1;
break;
}
how could i call this function and use it again for another pin like
step(2,200);
step(3,400);