What is wrong with this statement ?

hi guys

i have a small problem

my average range is +5 to -5

i have done

Serial.print (average);

and it is true

so haveing said that , why does this not work ???

  int val = average;
  
  if (val<previous)
  
 { 

  digitalWrite(dirpin, LOW);     // Set the direction.
  delay(100);

  int i;
  for (i = 0; i<average*2; i++)     
  {
    digitalWrite(steppin, LOW);  
    digitalWrite(steppin, HIGH); 
    delayMicroseconds(200);      
  }                              
 }
   else (val>previous)
 {
    digitalWrite(dirpin, HIGH);    // Change direction.
    delay(100);

  int i;
  for (i = 0; i<average*2; i++)       
  {
    digitalWrite(steppin, LOW);  
    digitalWrite(steppin, HIGH); .
    delayMicroseconds(200);     
  }  

          
}

my stepper only goes in 1 direction

can anybody help ??

thanks

skip

where do you assing current val to previous?

else (val>previous)

is not something that you want to do.

Maybe :

else  // (val>=previous)
digitalWrite(steppin, HIGH); .

Not sure what the period is doing in this statement.

for (i = 0; i<average*2; i++) won’t do anything when average <=0 . That is more likely when val<previous, which may explain why the motor only goes one way.