#include <Stepper.h>;
// sets constant intervals. sPR sets how far a revolution is for the stepper
const int stepsPerRevolution = 2052 ;
// sets the pin that checks the float switch
const int analogInPin = 0;
// resets clockwise rotation and counterclockwise. Set during later loops.
int rotationCW = 0;
int rotationCCW = 0;
// variable that corresponds to how far the switch has moved.
int floatSwitch = 0;
int location = 1;
// sets variable for stepper
Stepper myStepper = Stepper(stepsPerRevolution, 8, 10, 9, 11);
// setup for more stepper motor variables
void setup() {
myStepper.setSpeed(15);
Serial.begin(9600);
}
// loop to read the digital pin that the floatswitch is connected to
void loop() {
floatSwitch = digitalRead(6);
Serial.print("floatswitch = ");
Serial.println(floatSwitch);
delay(1000);
// if the floatswitch is on, this turns the gear to reduce water flow
if (floatSwitch == 1 && location == 1) {
rotationCW = 0.5 * stepsPerRevolution;
Serial.println("clockwise");
myStepper.step(rotationCW);
location = 2;
Serial.print("location = ");
delay(500);
Serial.println("At Location 1");
}
// if the floatswitch is turned off and the gear has been moved, this moves the gear back to
// return it to its regular flow rate.
else if (floatSwitch == 0 && location == 2); {
rotationCCW = -0.5 * stepsPerRevolution;
Serial.println("counterclockwise");
myStepper.step(rotationCCW);
location = 1;
Serial.print("location = ");
delay(500);
Serial.println("At Location 2");
}
else if (floatSwitch == 1 && location == 2 {
delay(1000)
rotationCCW = 0
myStepper.step(rotationCCW);
}
}
}