Gleiche Funktion
im Prizip sehr ähnlicher Programmaufbau
andere Variablennamen
const byte stepPin = 4;
const byte dirPin = 7;
unsigned long myStepTimer;
const unsigned long fullStepsRev = 200UL;
const unsigned long microsteps = 16UL;
const unsigned long stepsRev = fullStepsRev * microsteps;
const unsigned long rpm = 1;
const unsigned long pulseWaitMs = (1000UL * 60UL) / (stepsRev * rpm);
unsigned long PulseHighMicroSecs = 200;
void setup() {
pinMode(stepPin, OUTPUT); //Define pins and set direction
pinMode(dirPin, OUTPUT);
digitalWrite(dirPin, LOW);
}
void loop() {
if ( TimePeriodIsOver(myStepTimer,pulseWaitMs) ) {
oneStepPulse();
}
}
void oneStepPulse() {
digitalWrite(stepPin,HIGH);
delayMicroseconds(PulseHighMicroSecs);
digitalWrite(stepPin,LOW);
}
// easy to use helper-function for non-blocking timing
// explanation see here
// https://forum.arduino.cc/t/example-code-for-timing-based-on-millis-easier-to-understand-through-the-use-of-example-numbers-avoiding-delay/974017
boolean TimePeriodIsOver (unsigned long &startOfPeriod, unsigned long TimePeriod) {
unsigned long currentMillis = millis();
if ( currentMillis - startOfPeriod >= TimePeriod ) {
// more time than TimePeriod has elapsed since last time if-condition was true
startOfPeriod = currentMillis; // a new period starts right here so set new starttime
return true;
}
else return false; // actual TimePeriod is NOT yet over
}
damit haste jetzt funktionierenden Code aber null gelernt.
Ist das das was du willst?