Hi,
For one of my RC airplanes I need a gear/door sequencer to control the doors and gears. I already managed to get the code compiled as I would like it to operate, not tested in the airplane yet. Now I need some extra features that I would work into it.
Every time the Arduino boots up there are some servo’s that move, I would like to adjust my code so that everything stays in place as the last time I switched of the plane. So that the gear and doors stays in place and not move during the startup of the board. Is this possible to write something into the code?
Also I want that when the switch that controls the gears has moved the Arduino don’t do anything unless the switch has been moved into the last position when the Arduino was shut down.
Here is the code I wrote so far:
#include <VarSpeedServo.h>
VarSpeedServo ServoWielen;
VarSpeedServo ServoDeur_1;
VarSpeedServo ServoDeur_2;
int ServoIn;
int ServoUp;
int ServoDown;
const int PinServoInput = 8; //aansluiting RX kanaal
const int PinServoWielen = 10; //aansluiting wielen
const int PinServoDeur_1 = 12; //aansluiting deur servo hoofdpoten
const int PinServoDeur_2 = 11; // aansluiting deur servo neuspoot
void setup(){
pinMode(PinServoInput, INPUT);
// Serial.begin(9600);
ServoWielen.attach(PinServoWielen);
ServoDeur_1.attach(PinServoDeur_1);
ServoDeur_2.attach(PinServoDeur_2);
ServoWielen.writeMicroseconds(1000);
ServoDeur_1.slowmove(2000,150);
ServoDeur_2.slowmove(2000,150);
ServoUp = 1600; //wielen omhoog
ServoDown = 1400; //wielen omlaag
delay(50);
}
void loop(){
ServoIn = pulseIn(PinServoInput, HIGH, 21000);
if (ServoIn >= 1600) { // als servo input van RX hoger is of gelijk aan ga naar GearUp
goto WielenOmhoog;
}
else if (ServoIn <= 1400) { // als de servo input van de RX lager is of gelijk aan ga naar GearDown
goto WielenUit;
}
goto EndLoop;
WielenOmhoog:
{
ServoDeur_1.slowmove(1000,50); //wieldeur hoofdpoten openen
if (ServoIn >ServoUp){
delay (2000);
}
ServoWielen.writeMicroseconds(2000); //wielen omhoog
if (ServoIn >ServoUp){
delay (2000);
}
ServoDeur_1.slowmove(2000,50); //wieldeur hoofdpoten dicht
ServoDeur_2.slowmove(1000,50); //wieldeur neuspoot dicht
if (ServoIn <ServoDown){
delay (20);
}
goto EndLoop;
}
WielenUit:
{
ServoDeur_1.slowmove(1000,50); //wieldeur hoofdpoten open
ServoDeur_2.slowmove(2000,50); //wieldeur neuspoot open
if (ServoIn <ServoDown){
delay (2000);
}
ServoWielen.writeMicroseconds(1000); //wielen omlaag
if (ServoIn <ServoDown){
delay (2000);
}
ServoDeur_1.slowmove(2000,50); //wieldeur hoofdpoten dicht
if (ServoIn <ServoDown){
delay (20);
}
goto EndLoop;
}
EndLoop:
ServoUp = ServoIn + 100; // adds 100 to the current servo in value to help detect if it has changed
ServoDown = ServoIn -100;
}
Kind regards,
Ben