#include <Servo.h>
//Joystick pins
// int yPin = A0;
int xPin = A1;
// int sPin = 7;
// int yVal;
int xVal;
// int sVal;
//Servo motor pins
int servoPin = 6;
int servoPos;
Servo myServo;
//buzzer
int buzzPin = 5;
int delayTime = 1000;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
//pinMode(yPin, INPUT);
pinMode(xPin, INPUT);
// pinMode(sPin, INPUT);
pinMode(buzzPin, INPUT);
myServo.attach(servoPin);
}
void loop() {
// put your main code here, to run repeatedly:
xVal = analogRead(xPin);
servoPos = (180./1023.) * xVal;
myServo.write(servoPos);
// Serial.print("X-reading: ");
// Serial.print(xVal);
// Serial.print(" X-angle: ");
// Serial.print(servoPos);
// Serial.println("°");
if(servoPos == 180){
digitalWrite(buzzPin, HIGH);
}
else {
digitalWrite(buzzPin, LOW);
}
}