#include <MobaTools.h>
MoToServo topServo;
MoToServo bottomServo;
MoToServo flaps1;
MoToServo flaps2;
int flaps1Pin = 9;
int flaps2Pin = 6;
int switchPin = A3;
int switchStatus;
int yPin = A0;
int yPos;
int topServo_pin = 11;
int bottomServo_pin = 10;
int pos = 90;
void setup ( ) {
Serial.begin (9600);
topServo.attach (topServo_pin);
bottomServo.attach (bottomServo_pin);
flaps1.attach(flaps1Pin);
flaps2.attach(flaps2Pin);
topServo.write (pos);
pinMode (yPin, INPUT);
pinMode(3, INPUT);
}
void serialTextThingie() {
Serial.print("Joystick: ");
Serial.print(analogRead(A0));
Serial.print(" / Top Servo: ");
Serial.print(topServo.read());
Serial.print(" / Bottom Servo: ");
Serial.print(bottomServo.read());
Serial.print(" / pos: ");
Serial.print(pos);
Serial.print(" / Switch: ");
Serial.println(switchStatus);
}
void loop ( ) {
yPos = analogRead (yPin);
serialTextThingie();
if (yPos < 300) {
if (pos < 60) { } else {
pos = pos - 5;
topServo.write (pos);
bottomServo.write (pos);
serialTextThingie();
delay(5) ;
}
} if (yPos > 700) {
if (pos > 120)
{
}
else {
pos = pos + 5;
topServo.write (pos);
bottomServo.write (pos);
serialTextThingie();
delay(5);
}
}
switchStatus = digitalRead(switchPin);
delay(1);
if (switchStatus == 1) {
flaps1.write(40);
flaps2.write(40);
}
if (switchStatus == 0) {
flaps1.write(90);
flaps2.write(90);
}
}