The code controls a window blind open and closed. This works fine on arduino, but I get "soft WDT Reset Error" on the ESP8266.
I think it is to do with the delay / yield functions, but my limited programming skills have drawn a blank.
Any ideas:
/*
autoBLIND WITH SINGLE PUSH BUTTON OPERATION:
-> POWER ON, DO NOTHING
-> PRESS ONCE - BLIND CLOSE CYLCE (onboard LED on during cycle)
-> PRESS AGAIN - BLIND OPEN CYCLE (onboard LED on during cycle)
version: 0.9.1
Date: 15/06/2017
Changelog: FIXED - error outputs not going into low state after close
__________________________________________________________________________________*/
/*-----( Import needed libraries )-----*/
#include <Stepper.h>
// This will store the last known state of the button
const int buttonPin = D2; // change as per your button attached.
const int ledPin = LED_BUILTIN;
int x = 0;
// variables will change:
int buttonState = 0;
int oldButtonState = LOW;
/*---( Number of steps per revolution of INTERNAL motor in 4-step mode )*/
#define STEPS_PER_MOTOR_REVOLUTION 32
/*---( Steps per OUTPUT SHAFT of gear reduction -> 32steps motor x 64 Gear Ratio x 5 turn blind wand )---*/
#define STEPS_PER_OUTPUT_REVOLUTION 32*64*5 // 10240 steps
/*-----( Declare Stepper & Pins )-----*/
Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, D5, D7, D6, D8);
/*-----( Declare Variables )-----*/
int Steps2Take;
void setup() {
// initialize the button pin as a input:
pinMode(buttonPin, INPUT);
// initialize the LED as an output:
pinMode(LED_BUILTIN, OUTPUT);
// initialize serial communication:
Serial.begin(9600);
}
void loop() {
// Get the current state of the button
int newButtonState = digitalRead(buttonPin);
// Has the button gone high since we last read it?
if (newButtonState == HIGH && oldButtonState == LOW) {
while (x == 0) {
// Toggle on
digitalWrite(ledPin, HIGH);
Serial.println("Close_Cycle_Initiated");
Steps2Take = STEPS_PER_OUTPUT_REVOLUTION ; // Rotate closed
small_stepper.setSpeed(500);
small_stepper.step(Steps2Take);
yield();
digitalWrite(D5, LOW);
digitalWrite(D6, LOW);
digitalWrite(D7, LOW);
digitalWrite(D8, LOW);
yield();
digitalWrite(ledPin, LOW);
x = 1;
Serial.println("Close_Cycle_Complete");
}
while (x ==1) {
// Toggle off
digitalWrite(ledPin, HIGH);
Serial.println("Open_Cycle_Initiated");
Steps2Take = - STEPS_PER_OUTPUT_REVOLUTION; // Rotate open
small_stepper.setSpeed(500); // 700 a good max speed??
small_stepper.step(Steps2Take);
yield();
digitalWrite(D5, LOW);
digitalWrite(D6, LOW);
digitalWrite(D7, LOW);
digitalWrite(D8, LOW);
digitalWrite(ledPin, LOW);
Serial.println("Open_Cycle_Complete");
x = 0;
}
}
// Store the button's state so we can tell if it's changed next time round
oldButtonState = newButtonState;
}