Last active
July 10, 2017 11:27
-
-
Save Exchizz/f0a58542dfcbb7377039b09ae3843cd7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Stepper Motor Control - speed control | |
This program drives a unipolar or bipolar stepper motor. | |
The motor is attached to digital pins 8 - 11 of the Arduino. | |
A potentiometer is connected to analog input 0. | |
The motor will rotate in a clockwise direction. The higher the potentiometer value, | |
the faster the motor speed. Because setSpeed() sets the delay between steps, | |
you may notice the motor is less responsive to changes in the sensor value at | |
low speeds. | |
Created 30 Nov. 2009 | |
Modified 28 Oct 2010 | |
by Tom Igoe | |
*/ | |
#include <Stepper.h> | |
const int stepsPerRevolution = 6000; // change this to fit the number of steps per revolution | |
// for your motor | |
// initialize the stepper library on pins 8 through 11: | |
Stepper myStepper(stepsPerRevolution, 2,3); | |
int stepCount = 0; // number of steps the motor has taken | |
#define FAST_SPEED 1000 | |
#define SLOW_SPEED 100 | |
void setup() { | |
pinMode(2, OUTPUT); // Step shizzle | |
pinMode(3, OUTPUT); // Step shizzle | |
pinMode(4, INPUT); // button | |
pinMode(13, OUTPUT); // led | |
Serial.begin(115200); | |
} | |
int i = 1; | |
void loop() { | |
// Ramp up | |
if(i < FAST_SPEED && digitalRead(4) == HIGH){ | |
i++; | |
} | |
// Speed down if switch is pressed meaning cup is about to get filled... | |
if(digitalRead(4) == LOW){ | |
if(i > SLOW_SPEED){ | |
i-=2; | |
} | |
} | |
digitalWrite(13, digitalRead(4)); | |
myStepper.setSpeed(i); | |
Serial.println(i); | |
myStepper.step(stepsPerRevolution / 100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment