first commit
This commit is contained in:
56
servo.ino
Normal file
56
servo.ino
Normal file
@ -0,0 +1,56 @@
|
||||
#include <Servo.h>
|
||||
const int SW_pin = 2;
|
||||
//const int X_pin = A0;
|
||||
const int Y_pin = A1;
|
||||
const int buzzer = 12;
|
||||
const int led_1 = 11;
|
||||
int pos;
|
||||
|
||||
|
||||
Servo myServo;
|
||||
|
||||
|
||||
void setup() {
|
||||
pinMode(SW_pin, INPUT);
|
||||
digitalWrite(SW_pin, HIGH);
|
||||
Serial.begin(9600);
|
||||
myServo.attach(9);
|
||||
|
||||
pinMode(buzzer, OUTPUT);
|
||||
|
||||
pinMode(led_1, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
pos = analogRead(Y_pin);
|
||||
|
||||
|
||||
//Serial.println(pos);
|
||||
Serial.println(digitalRead(SW_pin));
|
||||
|
||||
if (pos > 530) {
|
||||
myServo.write(180);
|
||||
Serial.print("right");
|
||||
} else if (pos >= 500 && pos <= 530) {
|
||||
Serial.print("middle");
|
||||
myServo.write(90);
|
||||
} else if (pos < 500 ) {
|
||||
Serial.print("left");
|
||||
myServo.write(0);
|
||||
}
|
||||
|
||||
if (digitalRead(SW_pin) == 0) {
|
||||
digitalWrite(buzzer, HIGH);
|
||||
analogWrite(led_1, 255);
|
||||
} else {
|
||||
digitalWrite(buzzer, LOW);
|
||||
analogWrite(led_1, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//515-514 neutral
|
||||
//1023 max
|
||||
//0 min
|
||||
Reference in New Issue
Block a user