Created
December 30, 2023 15:20
-
-
Save tchilov/1fda877f06a317a67ea855004d4d07f2 to your computer and use it in GitHub Desktop.
startracker
This file contains hidden or 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
#include <Arduino.h> | |
#define DIR_PIN 39 | |
#define STEP_PIN 37 | |
//#define ENABLE_PIN 35 | |
#define MICROSTEPPING 32 | |
double revsPerSec = .01; | |
int timingUs = ((1000000 / revsPerSec) / (200 * MICROSTEPPING)) / 2; | |
void setup() { | |
pinMode(DIR_PIN, OUTPUT); | |
pinMode(STEP_PIN, OUTPUT); | |
pinMode(LED_BUILTIN, OUTPUT); | |
Serial.begin(9600); | |
} | |
void loop() { | |
digitalWrite(STEP_PIN, HIGH); | |
digitalWrite(LED_BUILTIN, HIGH); | |
delayMicroseconds(timingUs); | |
digitalWrite(STEP_PIN, LOW); | |
digitalWrite(LED_BUILTIN, LOW); | |
delayMicroseconds(timingUs); | |
if (Serial.available()) { | |
revsPerSec = Serial.parseFloat(); | |
Serial.println(revsPerSec, 4); | |
timingUs = ((1000000 / revsPerSec) / (200 * MICROSTEPPING)) / 2; | |
Serial.println(timingUs); | |
Serial.println(1000000 / revsPerSec); | |
Serial.println(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment