#include <Servo.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1 // 리셋 핀 없음
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Servo myServo;
const int potPin = A0;
const int buttonPin = 7;
int servoAngle = 0;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
myServo.attach(9);
Wire.begin();
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 10);
display.print("System Ready...");
display.display();
delay(1000);
}
void loop() {
int potValue = analogRead(potPin);
servoAngle = map(potValue, 0, 1023, 0, 180);
myServo.write(servoAngle);
display.clearDisplay();
display.setCursor(0, 10);
display.print("Servo Angle: ");
display.print(servoAngle);
display.display();
if (digitalRead(buttonPin) == LOW) {
myServo.write(90); // 버튼을 누르면 90도로 초기화
display.clearDisplay();
display.setCursor(0, 10);
display.print("Reset to 90 deg");
display.display();
delay(500);
}
}