#include <AccelStepper.h>
#include <Stepper.h>
AccelStepper stepper;
#define LED_PIN 2
#define LDR_PIN A0
const byte PositionPot = A0;
const byte AccelerationPot = A0;
// LDR Characteristics
const float GAMMA = 0.7;
const float RL10 = 50;
const int stepsPerRevolution = 2000;
Stepper myStepper(stepsPerRevolution, 6, 5, 4, 3);
void setup() {
pinMode(LDR_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
stepper.setMaxSpeed(1000);
stepper.setAcceleration(35);
}
void loop() {
int analogValue = analogRead(LDR_PIN);
float voltage = analogValue / 1024. * 5;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
myStepper.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
if (lux > 100) {
digitalWrite(LED_PIN, LOW);
} else {
digitalWrite(LED_PIN, HIGH); // turn the LED on (HIGH is the voltage level)
int analog_in = analogRead(PositionPot);
/*stepper.setAcceleration(analogRead(AccelerationPot));
stepper.moveTo(analog_in*199);
stepper.run();*/
myStepper.step(-stepsPerRevolution);
delay(0);
}
}