Demo entry 6354247

stepper motor

   

Submitted by anonymous on Apr 06, 2017 at 03:21
Language: C. Code size: 779 Bytes.

#include <Stepper.h>
// SET 2 BUTTON FOR CW AND CCW
int forward = 2;
int reverse = 3;
// SET PINS OF THE SETPPER MOTOR
const int stepsPerRevolution = 400;
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11); 
void setup() 
{
 //INITLALIZE THE PIN STATE OF THE BUTTON
 pinMode(forward,INPUT);
 pinMode(reverse,INPUT);
 digitalWrite(forward,LOW);

 digitalWrite(reverse,LOW);
 Serial.begin(9600);
 //SPEE OF THE STEPPER MOTOR
 myStepper.setSpeed(60);
}
void loop() 
{
 //READ THE STATE OF THE BUTTON
 int f = digitalRead(forward);
 int r = digitalRead(reverse);
 // CW
 if(f == HIGH && r == LOW)
 {
 myStepper.step(stepsPerRevolution);
 delay(500);
 }
 //CCW
 if(f == LOW && r== HIGH)
 {
 myStepper.step(-stepsPerRevolution);
 delay(500);
 }
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).