#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Servo.h>
Adafruit_SSD1306 display(128, 64, &Wire, -1);
Servo myServo;
const int angleOptions[] = {0, 45, 90, 135, 180};
const int numAngles = sizeof(angleOptions) / sizeof(angleOptions[0]);
int currentIndex = 0;
const int buttonPin = 2;
const int piezoPin = 8;
int angle = 0;
void setup() {
Serial.begin(9600);
myServo.attach(9);
pinMode(buttonPin, INPUT_PULLUP);
pinMode(piezoPin, OUTPUT);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("Ygol:");
display.display();
}
void loop() {
if (digitalRead(buttonPin) == LOW) {
currentIndex++;
if (currentIndex >= numAngles) {
currentIndex = 0;
}
angle = angleOptions[currentIndex];
myServo.write(angle);
tone(piezoPin, 1000, 200);
display.clearDisplay();
display.setCursor(0, 0);
display.print("Ygol:");
for (int i = 0; i < numAngles; i++) {
display.setCursor(0, (i + 1) * 10);
display.print(angleOptions[i]);
if (i == currentIndex) {
display.print(" <");
}
}
display.display();
delay(500);
}
}