Pages: [1]   Go Down
Author Topic: Help in Stepper motor control with push button  (Read 65 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi!
I'm quiet new  this programming.
I'm trying to rotate my stepper motor using a push button for a certain angle. The push button is deteced only st the beginning. the loop is not continue.
I need some urgent help pleeeeaseeeeeee...

Thank u in advance!

below is the code I'm using

#include <Stepper.h>

const int button=2;
const int stepsPerRevolution = 200;
int buttonState = 0;
Stepper myStepper(stepsPerRevolution,13, 12, 11, 10);
boolean section = false;

  void setup() {
  // set the speed at 60 rpm:
  myStepper.setSpeed(60);
  // initialize the serial port:
  Serial.begin(9600);
    pinMode(button, OUTPUT);
}
  
void loop(){
      buttonState = digitalRead(button);
if (buttonState==HIGH){  
  if(section==LOW){
    myStepper.step(100); // turningthe motor to 25 steps to get 45 degree rotaion
   section=true;

  }
}
 }
« Last Edit: April 18, 2014, 07:08:45 am by Malar58 » Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 49
Posts: 3420
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The problem is your section variable:
Code:
if(section==LOW){
    myStepper.step(100); // turningthe motor to 25 steps to get 45 degree rotaion
   section=true;

  }
Ignoring the fact that you're mixing up boolean values and LOW, the first time the button is pressed, section is false which happens to be zero, as is LOW, so the stepper steps and section is set to true (1). Next time the button is pressed, section isn't LOW any more and never will be again as you never change it, so the stepping portion isn't executed.

What is the section variable supposed to do?
Logged

Pages: [1]   Go Up
Jump to: