// Stepper motor on Wokwi!
#include <Stepper.h>
#include <LiquidCrystal_I2C.h>
#define LDR_PIN 2
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
int cw = 1;
int ccw = 5;
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
cw = 1;
pinMode(LDR_PIN, INPUT);
}
void loop() {
//Photo Input
if (digitalRead(LDR_PIN) == LOW)
{
Serial.print("Light!");
Serial.println("clockwise");
Serial.println(stepsPerRevolution);
cw = 2;
Serial.println(cw);
myStepper.step(stepsPerRevolution);
DelaySub();
}
else {
Serial.print("Dark ");
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
}
delay(1000);
}
void DelaySub() {
//whatever you want it to do
if (digitalRead(LDR_PIN) == LOW) {
delay(1000);
Serial.println("Delay Sub Run");
DelaySub();
}
else {
// Else do this
loop();
}
}