Select Git revision
WINDER_ADV.ino
WINDER_ADV.ino 5.20 KiB
#include <jled.h>
#include <AccelStepper.h>
#include <MultiStepper.h>
#include <AceButton.h>
using namespace ace_button;
#define ROTATIONS 1
#define ROT_R 2
#define ROT_L 2
#define ROT_STEPS 4096
#define ROT_SPEED 1000
#define ROT_ACCEL 800
#define ROT_PAUSE 4000
#define PAUSE_MIN 2
#define LED_PIN 5
#define SW_PIN 4
enum StateType
{
W_INIT, // 0
W_SETUP, // 1
W_IDLE, // 2
W_CYCLE, // 3
W_LEFT, // 4
W_RIGHT, // 5
W_STOP, // 6
W_PAUSE // 7
};
AccelStepper winder(8, 8, 10, 9, 11, false);
JLed pwr_led = JLed(LED_PIN).FadeOn(1000);
AceButton pwr_sw(SW_PIN);
int TargetPos = 0;
long StartTime = 0;
int Rotations = ROTATIONS;
StateType WState = W_INIT;
int Restart = false;
int Continue = false;
int StopWind = false;
int WaitMin = PAUSE_MIN;
void handleSwEvent(AceButton *, uint8_t, uint8_t);
void setup()
{
ButtonConfig *buttonConfig = pwr_sw.getButtonConfig();
WState = W_SETUP;
Serial.begin(9600);
pinMode(SW_PIN, INPUT_PULLUP);
buttonConfig->setEventHandler(handleSwEvent);
buttonConfig->setFeature(ButtonConfig::kFeatureClick);
buttonConfig->setFeature(ButtonConfig::kFeatureLongPress);
buttonConfig->setFeature(ButtonConfig::kFeatureSuppressAfterLongPress);
buttonConfig->setClickDelay(500);
winder.setMaxSpeed(ROT_SPEED);
winder.setAcceleration(ROT_ACCEL);
WState = W_IDLE;
}
void loop()
{
StateType old_state = WState;