#include <ESP_FlexyStepper.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
const int MOTOR_STEP_PIN = 19;
const int MOTOR_DIRECTION_PIN = 18;
const int SDA_PIN = 21;
const int SCL_PIN = 22;
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
// create the stepper motor object
ESP_FlexyStepper stepper;
// create an OLED display object connected to I2C
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
Wire.begin(SDA_PIN, SCL_PIN);
Serial.begin(115200);
// connect and configure the stepper motor to its IO pins
stepper.connectToPins(MOTOR_STEP_PIN, MOTOR_DIRECTION_PIN);
Serial.begin(9600);
// initialize OLED display with I2C address 0x3C
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("failed to start SSD1306 OLED"));
while (1);
}
}
void loop()
{
stepper.setSpeedInStepsPerSecond(100);
stepper.setAccelerationInStepsPerSecondPerSecond(100);
// Rotate forwards and display Good Morning
stepper.moveRelativeInSteps(2000);
oled.clearDisplay(); // Clear the display before showing new text
oled.setTextSize(1); // set text size
oled.setTextColor(WHITE); // set text color
oled.setCursor(0, 2); // Reset cursor
oled.println("Good Morning");
oled.display(); // Display buffer contents
delay(43200000); // Delay 12 hours (4.32e+7 milliseconds)
// Rotate backwards and display Good Night
stepper.moveRelativeInSteps(-2000);
oled.clearDisplay(); // Clear the display before showing new text
oled.setTextSize(1); // set text size
oled.setTextColor(WHITE); // set text color
oled.setCursor(0, 2); // Reset cursor
oled.println("Good Night");
oled.display(); // Display buffer contents
delay(43200000); // Delay 12 hours
}