Skip to content

Instantly share code, notes, and snippets.

@arifbalik
Last active November 25, 2020 07:26
Show Gist options
  • Save arifbalik/80355ae0155737c887d014e559c9d9bf to your computer and use it in GitHub Desktop.
Save arifbalik/80355ae0155737c887d014e559c9d9bf to your computer and use it in GitHub Desktop.
Rotary MEW
#define X_STEP_PIN 54
#define X_ENABLE_PIN 38
#define ANALOG_PIN 4
void setup(){
pinMode(X_STEP_PIN, OUTPUT);
pinMode(X_ENABLE_PIN, OUTPUT);
TCCR0A = _BV(COM2A1) | _BV(COM2B1) | _BV(WGM21) | _BV(WGM20); // non-Inverting PWM,
OCR0A = 255;
TCCR0B = _BV(WGM22) | _BV(CS21) | _BV(CS20); // Fast PWM and NO prescaling 16M/1024
OCR0B = 255;
digitalWrite(X_ENABLE_PIN, HIGH); // If motor does not work change this to LOW first.
}
bool state = false;
void loop(){
digitalWrite(X_STEP_PIN, state);
delayMicroseconds(map(analogRead(ANALOG_PIN), 0, 1023, 0, 255));
state = !state;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment