#include <Servo.h>//tell the arduino we will be using commands from
//the servo library
//we need to create our servo objects
int button_pin = 13;//sets up the button pin
int horz_pin = 9;//pin connected to the horizontal reading
int vert_pin = 10;//pin that recieves vertical signal
int joystick_horz_pin = A0;//pin for the joystick horizontal
int joystick_vert_pin = A1;//pin for the joystick vertical
Servo bottom_servo;//names the bottom servo (horizontal servo)
Servo top_servo;//names the top servo (vertical servo)
void setup() {
pinMode(button_pin, INPUT_PULLUP);/*INPUT_PULLUP attaches a resistor
to positive to button pin (pin 13 in this case). This is similar
to attaching a resistor to ground like we normally do for buttons
except it attaches to 5v so it reads 1 when not pressed and 0 when
it is pressed*/
bottom_servo.attach(horz_pin);//tells the arduino the bottom
//servo is at pin 9 same as pinMode for servos
top_servo.attach(vert_pin); //tells the arduino the top
//servo is at pin 10 same as pinMode for servos
Serial.begin(9600);//turns on the serial monitor
}
void loop() {
//put your main code here, to run repeatedly:
int vert_read = analogRead(vert_pin);
int button_read = digitalRead(button_pin);
Serial.print("button reading: ");
Serial.println(button_read);
if(button_read == 0){//this is how the arduino knows that the button is
//pressed
bottom_servo.write(180);//if the button is pressed, the bottom servo
//turns to position 180
top_servo.write(180);//if the button is pressed, the bottom servo
//turns to position 180
}
else{
bottom_servo.write(90);//if the button stays unpressed, the servo
//results back to it's original position, 90
top_servo.write(90);//if the button stays unpressed, the servo
//results back to it's origonal position, 90
}
}