#include <AccelStepper.h>
const int dirPin = 7;
const int stepPin = 6;
const int ms1 = 4;
const int ms2 = 2;
const int ms3 = 3;
const int photosensor_in = A0;
#define motorInterfaceType 1
const float GAMMA = 0.7;
const float RL10 = 50;
AccelStepper myStepper(motorInterfaceType, stepPin, dirPin);
int start_steps = 100;
int steps = start_steps;
unsigned long time = 0;
float prev_value = 0;
void setup() {
Serial.begin(9600);
pinMode(ms1, OUTPUT);
pinMode(ms2, OUTPUT);
pinMode(ms3, OUTPUT);
digitalWrite(ms1, LOW);
digitalWrite(ms2, LOW);
digitalWrite(ms3, LOW);
// put your setup code here, to run once:
myStepper.setMaxSpeed(1000);
myStepper.setAcceleration(200);
myStepper.setSpeed(100);
myStepper.moveTo(start_steps);
time = (millis() / 1000);
float analog_in = analogRead(photosensor_in);
prev_value = analog_in;
}
char* state = "NONE";
void loop() {
/* if (myStepper.distanceToGo() == 0) {
myStepper.moveTo(-200);
} */
time = (millis() / 1000);
float analog_in = analogRead(photosensor_in);
if (time != (millis() /1000) && analog_in > 278 && analog_in < 849){
Serial.println("DAY");
if (state != "DAY") {
steps = 70;
}
state = "DAY";
}
if (time != (millis() /1000) && analog_in > 4 && analog_in < 278){
Serial.println("NOON");
if (state != "NOON"){
steps = 90;
}
state = "NOON";
}
if (time != (millis() /1000) && analog_in > 850 && analog_in < 900){
Serial.println("NIGHT");
if (state != "NIGHT"){
steps = 50;
}
state = "NIGHT";
}
if (time != (millis() /1000) && analog_in > 900) {
Serial.println("MIDNIGHT");
if (state != "MIDNIGHT"){
steps = 50;
myStepper.moveTo(steps);
myStepper.run();
}
state = "MIDNIGHT";
}
if (myStepper.currentPosition() >= 200 * 1.05 || myStepper.currentPosition() <= 200 * 1.05) {
}
/* Serial.println(analog_in);
Serial.println(time); */
if (time != (millis() /1000) && state != "MIDNIGHT"){
Serial.println(analog_in);
myStepper.moveTo(steps += 1);
}
myStepper.run();
}