One of the features was a run time that can be set in 4 stages up to 30 seconds.
All went well, I tested the timer on the bench and in the air several times, and the motor cut at the set time every time. Just before the event, I decided that I wanted a 60s run time maximum, so I reprogrammed the Arduino accordingly.
So I travelled to Zwolle where the event was going to be held, an Old Warden style fun for all type of event. Weather was perfect, sunny skies, very little wind. There were a number of (untested) Ebenezer there, and we all had a ball trying them out and trimming. I kept the runs short to avoid having to walk a lot and jumping the water-filled ditches to recover the plane every time. I kept them to 25s max.
Then the mass fly-off was announced, and, eager to show off the steady circles my plane could fly, I raised the run time to 45s. Long story short: we spent 5-10 minutes with a group of people admiring the steady circling as the plane disappeared into the distance, never to be seen again (?).
So the motor did not cut, why? I think I now have found the mistake I made in the code. These are the essential lines:
Code: Select all
int readSwitch = 0;
unsigned long setTime;
void setup() {
readSwitch = 30; // run time in seconds
setTime = readSwitch * 1000; // run time in milliseconds
}
void loop() {
// stop motor when setTime is exceeded
}
It never occurred to me that the multiplication with 1000 would happen to readSwitch first, thereby potentially overflowing the limits of an int ( and causing a large negative number), and only then gets copied to "setTime". Unfortunately this happens somewhere between 30s and 45s input...... And to make things worse, setTime is an unsigned long, just a long would have prevented the motor to start in the first place.
In hindsight I wonder why I chose to use two different variables, a single unsigned long would have avoided all this.
As I said, an expensive lesson.......
Cheers,
Max.