Step Motor - Serial step controlled


hi, i'm working on project need control step motor serial monitor,
what i've done far doesn't seen work, stepper move number of steps with
one digit number (0 - 9), , if try use more one, program sums digits, example, if type 12, move 3 steps.

also, can't use negative numbers apparently.

please help!

#include <stepper.h>
#include <stdlib.h>
#define steps 200
stepper motor(steps, 8, 9, 10, 11);
int i=0, g;
char ascii[10];
void setup() {
  serial.begin(9600);
  motor.setspeed(1);

}

void loop() {
 
  if(serial.available() > 0){
    for(i=0;i<10;i++){
      ascii=serial.read();
      if((ascii!='-')&&(ascii!='.')&&(ascii!='0')&&(ascii!='1')&&(ascii!='2')&&(ascii!='3')&&(ascii!='4')&&(ascii!='5')&&(ascii!='6')&&(ascii!='7')&&(ascii!='8')&&(ascii!='9')){
      ascii='\0';
    }
    //int g = atoi(ascii);
    int g = atoi(ascii);
    motor.step(g);
  }
}

example 4 of serial input basics shows how read multi digit number serial port. 


Arduino Forum > Using Arduino > Programming Questions > Step Motor - Serial step controlled


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts