Pages: [1]   Go Down
Author Topic: press button stepper moved 360 steps  (Read 135 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Guys/Girls, I am a total noob here and have read and tried to understand what I have done wrong here and cant figure it out, if  you are able to hep it is much appreciated.
the code:

Code:
#include <AccelStepper.h>
int ButtonA;
AccelStepper stepper(1, 9, 10); //pin 9step, pin10 direction
int pos = 360;
int ButtonAState = 0;


void setup()
{                
  pinMode(4,INPUT);
  //pinMode(5,INPUT);
  pinMode(10, OUTPUT);     //10 is direction
  pinMode(9, OUTPUT);    //9 is step
  stepper.setMaxSpeed(5000);
  stepper.setSpeed(50);  
  stepper.setAcceleration(9000000);
}

void loop(){
  
val = digitalRead(ButtonA); //Reads state of button
//Check if button is pressed
if (val == HIGH) {
 stepper.runToNewPosition(pos);
 
 delay(50);
 
}
I am trying to make the stepper turn 360 steps each tiem buttonA is pressed.
thanks.
« Last Edit: August 05, 2014, 02:32:19 am by jrslick22 » Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34726
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Read
1) the how to use this forum sticky to learn how to post code.
2) the documentation on the accel libary - when using it you are supposed to make repeated calles to a function until the motor has got to its correct position. You will need a while loop inside your if statement to do this.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Rodger that, thanks for the help

I'm not asking for help with how to get a stepper to move, I have that working, I am asking for help to tie this to a momentary switch

thx
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34726
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You are just looking at the level from the switch. You need to look at the edge. That is when the button changes from a low to a high.
To do this store the previous value of the button and only move the motor when the current value is high and the previous value was low.
Look in the IDE for an example called change.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you mate, will do.
Logged

Pages: [1]   Go Up
Jump to: