 const int C = 10;
 const int D = 11;
 
-void wave_step(const unsigned* spd, const unsigned* steps, const boolean* cw);
+class State
+{
+  public:  
+  unsigned spd;
+  unsigned steps;
+  boolean  running;    
+  boolean  cw;
+};
 
-void setup() {                
+void wave_step(const State* state);
+
+void setup() 
+{                
   pinMode(A, OUTPUT);     
   pinMode(B, OUTPUT);     
   pinMode(C, OUTPUT);     

    c %= 4;
    d %= 4;

    delay(10000/(*spd));
  }
}



void loop() 
{
  
  State state;
  state.spd = 300;
  state.steps = 50;
  state.running = true;
  state.cw = true;
  
  wave_step(&state);

  while(true);
}

//!  speed range: [10,500]
void wave_step(const State* state)
{
  //!  specify the starting index according to the direction
  unsigned a,b,c,d;
  a = 0;
  b = 2;
  c = state->cw?  3  :  1;
  d = state->cw?  1  :  3;
  
  //!  move steps as specified if running == true.
  boolean arr[4] = {1,0,0,0};
  unsigned count = state->steps;
  while(count-- > 0 && state->running)
  {
    digitalWrite(A, arr[a++]);
    digitalWrite(B, arr[b++]);
