#include <WiFi.h>
#include <Adafruit_SSD1306.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C LCD = LiquidCrystal_I2C(0x27, 16, 2);
char ssid[] = "Wokwi-GUEST"; // your network SSID (name)
char pass[] = ""; // your network password
#define NTP_SERVER "pool.ntp.org"
#define UTC_OFFSET 0
#define UTC_OFFSET_DST 0
#define STEP_PIN 4
#define DIR_PIN 5
#define DIR_PIN2 4
#define STEP_PIN2 5
void printLocalTime() {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
LCD.setCursor(0, 1);
LCD.println("Connection Err");
return;
}
LCD.setCursor(8, 0);
LCD.println(&timeinfo, "%H:%M:%S");
LCD.setCursor(0, 1);
LCD.println(&timeinfo, "%d/%m/%Y %Z");
}
// VCC to 12 V power supply
void initWiFi() {
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, pass);
// WiFi.begin("Wokwi-GUEST", "");
Serial.print("Connecting to WiFi ..");
while (WiFi.status() != WL_CONNECTED) {
Serial.println(WiFi.status());
Serial.print('.');
delay(1000);
}
Serial.println("Connected");
Serial.println(WiFi.status());
Serial.println(WiFi.localIP());
Serial.print("RRSI: ");
Serial.println(WiFi.RSSI());
}
void setup() {
// initialize the serial port:
Serial.begin(115200);
Wire.begin(10, 8);
LCD.init();
LCD.backlight();
LCD.setCursor(0, 0);
initWiFi();
pinMode(STEP_PIN, OUTPUT);
pinMode(DIR_PIN, OUTPUT);
digitalWrite(STEP_PIN, LOW);
LCD.clear();
LCD.setCursor(0, 0);
LCD.println("Online");
LCD.setCursor(0, 1);
LCD.println("Updating time...");
configTime(UTC_OFFSET, UTC_OFFSET_DST, NTP_SERVER);
}
void loop() {
digitalWrite(DIR_PIN, HIGH);
digitalWrite(DIR_PIN2, HIGH);
for (int i = 0; i < 200; i++) {
digitalWrite(STEP_PIN, HIGH);
digitalWrite(STEP_PIN, LOW);
delay(5); // 5 ms * 200 = 1 second
}
delay(500); // Wait half a second
// Move 200 steps (one rotation) CCW over 400 millis
digitalWrite(DIR_PIN, LOW);
digitalWrite(DIR_PIN2, LOW);
for (int i = 0; i < 200; i++) {
digitalWrite(STEP_PIN, HIGH);
digitalWrite(STEP_PIN, LOW);
delay(2); // 2 ms * 200 = 0.4 seconds
}
delay(1000); // Wait another second
printLocalTime();
delay(250);
}