// Servo Sweep example for the ESP32
// https://wokwi.com/arduino/projects/323706614646309460
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
#include <ESP32Servo.h>
#include <RTClib.h>
Servo s1;
Servo s2;
Servo s3;
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Domingo", "Segunda", "Terca", "Quarta", "Quinta", "Sexta", "Sabado"};
void setup() {
Serial.begin(115200);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
delay(2000);
display.clearDisplay();
s1.attach(18);
s2.attach(13);
s3.attach(5);
Serial.begin(115200);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
}
int pos = 0;
void loop() {
DateTime now = rtc.now();
Serial.print("Current time: ");
Serial.print(now.day(), DEC);
Serial.print("/");
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.year(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.println();
delay(0);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(7, 7);
// Display static text
display.println ((String) now.day()+"/"+now.month()+"/"+ now.year()+" ("+daysOfTheWeek[now.dayOfTheWeek()]+") ");
display.setCursor(50, 27);
display.println ((String) now.hour()+":"+now.minute());
delay(60);
display.display();
for (pos = 0; pos <= 180; pos += 1) {
s1.write(pos);
delay(15);
}
for (pos = 180; pos >= 0; pos -= 1) {
s1.write(pos);
delay(15);
}
s1.detach ();
for (pos = 0; pos <= 180; pos += 1) {
s2.write(pos);
delay(15);
}
for (pos = 180; pos >= 0; pos -= 1) {
s2.write(pos);
delay(15);
}
s2.detach ();
for (pos = 0; pos <= 180; pos += 1) {
s3.write(pos);
delay(15);
}
for (pos = 180; pos >= 0; pos -= 1) {
s3.write(pos);
delay(15);
}
s3.detach ();
}