/*
0.96 inch SSD1306 OLED display
Pin --> ESP32
Vin --> 3.3V
GND --> GND
SCL --> GPIO 22
SDA --> GPIO 21
*/
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <ESP32Servo.h>
const int servoPin = 18;
Servo servo;
const int relayPin = 26;
// Configuración de la pantalla OLED
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 pantalla(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
// put your setup code here, to run once:
servo.attach(servoPin, 500, 2400);
// Set pins as output.
pinMode(relayPin, OUTPUT);
Serial.begin(115200);
Serial.println("Hello, ESP32!");
// configura la pantalla para recibir datos
if(!pantalla.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
}
void loop() {
pantalla.clearDisplay();
pantalla.setTextColor(WHITE);
pantalla.setTextSize(1);
// Activate the relays one by one for one second.
// The relay module simulates a module that
// is activated with a high level at the "IN" pin.
digitalWrite(relayPin,HIGH); // Activate relay.
delay(1000);
digitalWrite(relayPin,LOW); // Release the relay.
delay(1000);
// put your main code here, to run repeatedly:
delay(0); // this speeds up the simulation
int pos = 0;
for (pos = 0; pos <= 180; pos += 1) {
servo.write(pos);
Serial.println(pos);
pantalla.setCursor(5,5);
pantalla.print(pos);
pantalla.display();
delay(15);
pantalla.clearDisplay();
}
for (pos = 180; pos >= 0; pos -= 1) {
servo.write(pos);
Serial.println(pos);
pantalla.setCursor(5,5);
pantalla.print(pos);
pantalla.display();
delay(15);
pantalla.clearDisplay();
}
pantalla.display();
}