{solved}problem with While Loop


i having issue while loop stepperhome function.  called once on bootup.  moves -100 steps back, program stops there, until manually hit endstop.  supposed loop , move -100 until hits endstops.

am missing something?
code: [select]
#include <accelstepper.h>

accelstepper stepper1(1, 9, 8);

const int homebutton = 19;
byte hbval;


void setup(){
  serial.begin(9600); // debugging
  stepper1.setmaxspeed(500); //nice , slow testing
  stepper1.moveto(-3200);
  stepper1.setacceleration(500);
  pinmode(homebutton, input_pullup);
 
  stepperhome(); //runs routine home motor
}
void loop(){
    stepper1.moveto(46000); // random position end testing
  stepper1.runtoposition();
  delay(1000);
  stepper1.moveto(0);
  stepper1.runtoposition();
  delay(1000);
}



void stepperhome()
{ //this routine should run motor
   // in setup()
                                   // before calling stepperhome function
  hbval = digitalread(homebutton);
  while (hbval == high)
  {
    //backwards till hits switch , stops
    stepper1.moveto(-100);
    stepper1.run();
    hbval = digitalread(homebutton);
  }
 
  stepper1.setcurrentposition(0); //
}

got it,  moveto needed move() .

always somethign simple


Arduino Forum > Using Arduino > Programming Questions > {solved}problem with While Loop


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'