I am currently working on a project that involves using arduino to autonomously control a boat. But before we start controlling the boat with arduino, we need to first arm the boat.. i.e make sure the thrusters and rudders are working fine and we only want to do this once. But because the code to arm the boat is in the void loop() ... it would keep on repeating and thats where i need your help.. Is there a way to check if the boat has been armed once, it should stop and move to the next part of the program.. Below is the code i have already worked, obviously its not working.. Really need your help you guys .. Thanks ..
//First Stage Autonomous Control of Rover Boat
#include <Servo.h>
Servo Rudders; // Note rudders are controlled together not individually
Servo fThrust1; // Starboard ducted fan
Servo fThrust2; // Port ducted fan
Servo rThrust; // Reverse engine
// Min and Max servo position in microseconds
int minPulse = 850; // Approx. abs(min) settings: 800 Pulse 17 position
int maxPulse = 2250; // Approx. abs(max) settings: 2280 Pulse 180 position
boolean armed = false;
void setup()
{
// Attach each Servo object to a digital pin
Rudders.attach(9, minPulse, maxPulse);
fThrust1.attach(10, minPulse, maxPulse);
fThrust2.attach(10, minPulse, maxPulse);
rThrust.attach(11, minPulse, maxPulse);
Either put the arming code in the setup() function where it will only run once or, if it must be in the loop() function, set a global variable, let's call it OKtoArm, to true at the start of the program, check it before running the arming code, only arm if it is true then, as part of the arming process set it to false to stop it running again.
Looking at your code it works the second way and looks OK apart from the fact that you do not set armed to true once you had armed the motor.