#include <LiquidCrystal.h>
#include <AccelStepper.h>
#include <Bounce2.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
AccelStepper myStepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
#define NUM_SWITCHES 5
const int endSwitchPin[NUM_SWITCHES] = {A0, A1, A2, A3, A4};
Bounce2::Button endSwitch[NUM_SWITCHES] = {Bounce2::Button()};
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2);
for(byte i = 0; i < NUM_SWITCHES; i++)
{
endSwitch[i].attach(endSwitchPin[i], INPUT_PULLUP);
endSwitch[i].setPressedState(LOW);
endSwitch[i].interval(5);
}
for(byte i = 0; i < NUM_SWITCHES; i++)
{
endSwitch[i].update();
int switchState = endSwitch[i].read();
if (switchState == HIGH) // endSwitch disconnected!
{
lcd.setCursor(0, 0);
lcd.print("End");
lcd.print(i);
lcd.print(" not working");
while(1);
}
}
myStepper.setMaxSpeed(1000);
myStepper.setAcceleration(50);
myStepper.setSpeed(100);
for(byte i = 0; i < NUM_SWITCHES; i++)
{
lcd.setCursor(0, 0);
lcd.print("Moving to end ");
lcd.print(i);
while (endSwitch[i].read() == LOW)
{
endSwitch[i].update();
myStepper.move(10000);
myStepper.run();
delay(5);
}
}
lcd.setCursor(0, 0);
lcd.print("Moving Complete!");
}
void loop()
{
}