#include <Servo.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// Pin definitions
const int servoPin = 9; // Pin where the servo is connected
// Create an instance of the SSD1306 display
#define SCREEN_WIDTH 128 // Change to your display width
#define SCREEN_HEIGHT 64 // Change to your display height
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); // -1 for no reset pin
Servo myservo;
void setup() {
// Initialize the servo
myservo.attach(servoPin); // Use the defined servo pin
// Initialize the display
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x64
display.clearDisplay(); // Clear the display buffer
// Display the project name
display.setTextSize(1); // Set text size
display.setTextColor(SSD1306_WHITE); // Set text color
display.setCursor(0, 0); // Set cursor position
display.print("Rudi Hidayat,S.Pd.,MT");
display.setCursor(0, 10); // Move cursor to the next line
display.print("Tugas 14 Motor Servo");
display.setCursor(0, 20); // Move cursor to the next line
display.print("Embedded System");
display.setCursor(0, 40); // Set cursor position
display.print("Yofrianto");
display.setCursor(0, 50); // Move cursor to the next line
display.print("1083241006");
display.display(); // Show the text on the display
delay(6000); // Fixed missing semicolon
}
void loop() {
// Move the servo to 0 degrees
myservo.write(0);
delay(1000); // Wait for 1 second
// Move the servo to 90 degrees
myservo.write(90);
delay(1000); // Wait for 1 second
// Move the servo to 180 degrees
myservo.write(180);
delay(1000); // Wait for 1 second
// Move the servo back to 90 degrees
myservo.write(90);
delay(1000); // Wait for 1 second
}