I'm building a radio controlled plane, and will be adding navigation lights:
2 wing tip strobes, double flash and out of sequence with each other,
A tail strobe that flashes about once a second,
A red anti collision light that mimicks a revolving light on the belly of the plane, this is to ramp up in brightness, flash at full brightness then ramp back down. simulating seeing the revolving light rotate and flash in your eyes.
Then the usual red and green wing tip lights and a white facing backwards, on constant,
And eventually landing lights that switch on when the flaps are deployed.. so the arduino will be monitoring the reciever... but thats for later, as i'm having a problem with the simulated revolving belly light running far too fast.
I've taken someone elses code originally written in 2011 which monitored the reciever, turned the nav lights on when a certian servo position was read, and turned the landing lights on when another servo position was read,
BUT i don't have the reciever yet, so can't test that.
So i stripped out the servo position monitoring portion of the code, and i have the strobes working exactly how i want, but the revolving belly light just does not run slow enough to see the effect, and i can't figure out how to slow it down.
This is the code i'm running now,
I believe i need to slow the timer down that the belly strobe runs on?
long currentTime = 0;
//Navigation Lights
int tailNavLight = 4; //White constant on
int portNavLight = 5; //Red constant on
int starboardNavLight = 6; //Green constant on
//Revolving Belly Light
int RevolvingLight = 3; //Replicates revolving light (analog)
int RevolvingLighteInterval = 0;
int RevolvingLightDirection = HIGH;
//WingTipStrobe Strobe 1
int WingTipStrobe1 = 7; //Flashes twice every second or so
long WingTipStrobeTimer1 = millis();
long WingTipStrobeInterval1 = 2000;
int WingTipStrobePhase1 = 1;
//WingTipStrobe Strobe 2
int WingTipStrobe2 = 8; //Flashes twice every second or so
long WingTipStrobeTimer2 = millis();
long WingTipStrobeInterval2 = 2100;
int WingTipStrobePhase2 = 1;
//Tail strobe
int TailStrobe = 9; //Flashes once a second or so
long TailStrobeTimer = millis();
long TailStrobeInterval = 2300;
int TailStrobePhase = 1;
void setup()
{
Serial.begin(115200);
currentTime = millis();
pinMode(portNavLight, OUTPUT);
pinMode(starboardNavLight, OUTPUT);
pinMode(WingTipStrobe1, OUTPUT);
pinMode(WingTipStrobe2, OUTPUT);
pinMode(TailStrobe, OUTPUT);
pinMode(RevolvingLight, OUTPUT);
pinMode(tailNavLight, OUTPUT);
digitalWrite(portNavLight, HIGH);
digitalWrite(starboardNavLight, HIGH);
digitalWrite(tailNavLight, HIGH);
}
void loop()
{
currentTime = millis();
//Belly Light
{
analogWrite(RevolvingLight, RevolvingLighteInterval);
if (RevolvingLightDirection == HIGH)
RevolvingLighteInterval = RevolvingLighteInterval + 5;
else
RevolvingLighteInterval = RevolvingLighteInterval - 5;
if (RevolvingLighteInterval > 180 && RevolvingLightDirection == HIGH )
RevolvingLighteInterval = 255; //Jump for the flash
if (RevolvingLighteInterval > 220 && RevolvingLightDirection == LOW )
RevolvingLighteInterval = 180; //Dump from the flash
if (RevolvingLighteInterval == 255)
RevolvingLightDirection = LOW;
if (RevolvingLighteInterval == 0)
RevolvingLightDirection = HIGH;
{
Serial.print("Revolving Light value: ");
Serial.println(RevolvingLighteInterval);
}
}
//White Strobe 1
if(currentTime-WingTipStrobeTimer1 > WingTipStrobeInterval1 )
{
switch(WingTipStrobePhase1)
{
case 1:
//strobe on first
digitalWrite(WingTipStrobe1, HIGH);
WingTipStrobeInterval1=50;
WingTipStrobePhase1 = 2;
break;
case 2:
//strobe off first cycle
digitalWrite(WingTipStrobe1, LOW);
WingTipStrobeInterval1=100;
WingTipStrobePhase1 = 3;
break;
case 3:
//strobe on second cycle
digitalWrite(WingTipStrobe1, HIGH);
WingTipStrobeInterval1=50;
WingTipStrobePhase1 = 4;
break;
case 4:
//strobe off second cycle
digitalWrite(WingTipStrobe1, LOW);
WingTipStrobeInterval1=2000;
WingTipStrobePhase1 = 1;
break;
}
WingTipStrobeTimer1=millis();
}
//White Strobe 2
if(currentTime-WingTipStrobeTimer2 > WingTipStrobeInterval2 )
{
switch(WingTipStrobePhase2)
{
case 1:
//strobe on first
digitalWrite(WingTipStrobe2, HIGH);
WingTipStrobeInterval2=50;
WingTipStrobePhase2 = 2;
break;
case 2:
//strobe off first cycle
digitalWrite(WingTipStrobe2, LOW);
WingTipStrobeInterval2=110;
WingTipStrobePhase2 = 3;
break;
case 3:
//strobe on second cycle
digitalWrite(WingTipStrobe2, HIGH);
WingTipStrobeInterval2=50;
WingTipStrobePhase2 = 4;
break;
case 4:
//strobe off second cycle
digitalWrite(WingTipStrobe2, LOW);
WingTipStrobeInterval2=2300;
WingTipStrobePhase2 = 1;
break;
}
WingTipStrobeTimer2=millis();
}
//Tail Strobe
if(currentTime-TailStrobeTimer > TailStrobeInterval )
{
switch(TailStrobePhase )
{
case 1:
//strobe on
digitalWrite(TailStrobe, HIGH);
TailStrobeInterval=70;
TailStrobePhase = 2;
break;
case 2:
//strobe off
digitalWrite(TailStrobe, LOW);
TailStrobeInterval=1800;
TailStrobePhase = 1;
break;
}
TailStrobeTimer=millis();
}
}