Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CheapStepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
#include "Arduino.h"
#include "CheapStepper.h"

#if defined(ESP8266) || defined(ARDUINO_ESP8266_NODEMCU)
#define YIELD_TIME 1000 // Source https://www.sigmdel.ca/michel/program/esp8266/arduino/watchdogs_en.html#ESP8266_WDT_TIMEOUT
#else
#define YIELD_TIME (0UL - 1UL) // Large number to only call it rarely
#endif

CheapStepper::CheapStepper () : pins({8,9,10,11}) {
for (int pin=0; pin<4; pin++){
Expand Down Expand Up @@ -157,6 +162,14 @@ void CheapStepper::step(bool clockwise){

if (clockwise) seqCW();
else seqCCW();

// return control to the system between the steps so that long series of those
// doesn't trigger watch dog restart on ESP
if (millis() - lastYieldTime >= YIELD_TIME)
{
yield();
lastYieldTime = millis();
}
}

void CheapStepper::off() {
Expand Down