Skip to content

Instantly share code, notes, and snippets.

@L-four
Forked from Bumblefuck/arduino spindexer
Last active January 30, 2017 00:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save L-four/541ba77c7d22d7a39ea117eb8b5d79aa to your computer and use it in GitHub Desktop.
Save L-four/541ba77c7d22d7a39ea117eb8b5d79aa to your computer and use it in GitHub Desktop.
/*
Rotates through 480 steps every time the button is pressed.
Check your equipment to find out how many motor steps it takes for a full rotation. In my case it's 4800.
4800/sides or gear teeth you need to cut = number to put into "const int pulseset"
*/
int count = 0;
const int pulseset = 480; //change this to change how many sides/gear teeth. 4800 pulses per rotation on my spindexer.
const int directionPin = 8;
const int pulsePin = 9; // the stepper driver gives one step at the rising edge of the pulse from the Arduino.
const int sensorValue = 1000; // sets the speed of rotation. 1000 is slow, 10 is fast
const int buttonPin = 7;
int button = 1;
void setup() {
pinMode(directionPin, OUTPUT);
pinMode(pulsePin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
count = 0;
button = digitalRead (buttonPin);
if (button == LOW) {
digitalWrite (directionPin, HIGH);
while ( count < pulseset) {
digitalWrite(pulsePin, HIGH);
delayMicroseconds(sensorValue);
digitalWrite(pulsePin, LOW);
delayMicroseconds(10);
count ++;
}
}
count = 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment