Hier ein fertiger Sketch für eine Flugzeugbeleuchtung, angelehnt an die manntragende Fliegerei.
Es werden 4 Lampengruppen bedient:
- ACL ( Immer an, solange Stron da ist )
- NAV-Lichter ( hinten weiß, links rot, rechts Grün )
- Strobes, Bltzlichter
2 und 3 werden hier gmeinsam geschaltet, damit man alles mit einem Steuerkanal, 3-Positions-Schalter erledigen kann.
- Landescheinwerfer
Wer mag, kann den Sketch gern nutzen.
Folgende Anmerkungen:
Wer in meinem Code Spaghetti findet, darf sie auch aufessen.
Ich bin blutiger Anfänger, und als ich das geschrieben habe, hielt ich millis noch für Bakterien, und Timer für Armbanduhren.
Trotzdem funktioniert es prima!
Hinweise:
-
Direkt am Anfang hinter void Loop() steht "// goto Mainloop"
Wenn man dort die // wegnimmt, schaltet man den für mache einen nervigen Lampen Blitz-blinkt-
rotier Test aus.
-
Die Strobes stehen dort mit einem Blitz/Pauseverhältnis von 40/60ms
Man kann das ändern, und solange die Summe 100 beträgt, also z.B. 70/30
( was die Blitze aber dunkler werden läßt ) oder 50/50, ist alles gut.
Sobald die Summe anders ist z.B. 60/60, ergibt ja 120mS, dann muss im Loop davor ( ACL only )
unten die Delay-Zeit angepasst werden. Sie beträgt Summe * 4, ( jetzt 400, dann also 480 )
Bei 40/40 ensprechend 320 ( 40+40 )*4
Für Anfänger empfehle ich den Sketch zweimal abzuspeichern, und einen zum experimentieren zu verwenden.
Viel Spaß beim Fliegen damit. Sieht mit ensprechender Außenbeschaltung und Powerled´s echt gut aus, auch an hellen Tagen.
/*
Scale like anticollision-light, strobe-light, NAV-lights and landing-light for RC-Aircraft
Free to use by everyone!
Skyfox60
Digital Channels Output
NAV_light = D5 ( Left = red, Right = green, Back = white ) digital out
ACL = D6 PWM _ Channel for intensity regulation ( ACL = Anticollision Light )
Landinglight = D7 digital out
Strobe = D8 digital out
Receiverchannel Inputs:
Input a Servochannel from Receiver to D10, Try-State Switch is recommended ( 1000µs, >1500µs, 2000µs )
In normal ( out ) condition ( a > 1600µS a <2100µS ) only the mainloop and ACL_only-routine is ruinning.
This makes the ACL ( anticollision-light ) running as soon as the battery is plugged on and the lamp-test ist finished.
I made this because in real aircraft the first action after switching the main switch on, is to activate the ACL, there should be no need to activate a switch at the transmitter for that.
Also, the ACL remains Fading up and down, until battery is unplugged and aircraft save.
If you have a transmitter that allowes the switch-position-test at the beginning, set it so that the light switch has to be in 2000µs position before transmitter starts.
When switch in appx mid position ( a <1400 ) the ACL_NAV_Strobe-Loop runs. You find at first a similar routine like in ACL_only.
This was required due to the need of some other values to have the same visiual appearence of ACL the and nearly continuing as it was.
there is a Lamptest to check all lamps. 10 flashes wake up for you, followed by single test and finally 10 flashes to finish and exit to Mainloop.
*/
int NAV_light = 5;
int ACL = 6; // the PWM pin the LED is attached to
int Landinglight = 7;
int Strobelight = 8;
int brightness = 7; // how bright the LED is, 0 at startup
int brightness_increment = 7; // How many points increment or decrement per step to fade the LED, if you change this value ( default is 7 ), you have also to change the counter1 steps ( default is 68 ), just for the case you changed it and do not remember
// Also max Brightness has to be altered, if you cange any of the values. ( default is 231 )
int counter1 = 1;
int counter2 = 0;
void setup()
{
pinMode(5, OUTPUT); // NAV_light
pinMode(6, OUTPUT); // output ACL
pinMode(7, OUTPUT); // output Landinglight
pinMode(8, OUTPUT); // putput Strobelight
pinMode(10, INPUT); // reads a and cycles ACL and Strobelight
//Serial.begin(9600);
}
void loop() {
//goto Mainloop;// set this line as // to execute the lamptest before start, otherwise it starts without lamptest. Your choice
// Lamptest to check all lamps. 10 flashes wake up for you, then single test and then 10 flashes finish and exit to Mainloop
for ( int L1 = 0; L1 <= 10; L1++ )
{
digitalWrite (Strobelight,HIGH); ; digitalWrite(NAV_light, HIGH); digitalWrite(ACL, HIGH); digitalWrite(Landinglight, HIGH); delay(50);
digitalWrite (Strobelight,LOW); digitalWrite(NAV_light, LOW); digitalWrite(ACL, LOW); digitalWrite(Landinglight, LOW);delay(50);
}
for ( int L = 0; L <= 1; L++) { digitalWrite (NAV_light, HIGH); delay(300); digitalWrite (NAV_light, LOW);delay(300); digitalWrite ( ACL, HIGH ); delay(300); digitalWrite ( ACL, LOW );delay(300); digitalWrite (Landinglight,HIGH);
delay(300); digitalWrite (Landinglight,LOW);delay(300); digitalWrite (Strobelight,HIGH);delay(300);digitalWrite (Strobelight,LOW);delay(300);
}
for ( int L1 = 0; L1 <= 10; L1++ )
{
digitalWrite (Strobelight,HIGH); ; digitalWrite(NAV_light, HIGH); digitalWrite(ACL, HIGH); digitalWrite(Landinglight, HIGH); delay(50);
digitalWrite (Strobelight,LOW); digitalWrite(NAV_light, LOW); digitalWrite(ACL, LOW); digitalWrite(Landinglight, LOW);delay(50);
}
Mainloop:;
counter1 = 1;
counter2 = 0;
int a = pulseIn(10,HIGH,25000); // Read in pulse lenght, 3rd parameter has to be finetuned with receiver behavior
if ( a >=1600 & a <=2100 ) { digitalWrite (NAV_light, LOW); digitalWrite (Landinglight, LOW); goto ACL_only; }
if ( a >950 & a <1200 ) digitalWrite (Landinglight, HIGH);
if ( a >1200 ) { digitalWrite (Landinglight, LOW); }
if ( a >=950 & a <=1600) { digitalWrite (NAV_light, HIGH); goto ACL_NAV_Strobe; }
ACL_only:;
analogWrite(brightness, 7);
for (brightness <=7; brightness <252; brightness = brightness + brightness_increment) { analogWrite(ACL, brightness); delay(20); Serial.println(brightness); }
for (brightness <=253; brightness >=7; brightness = brightness - brightness_increment){ analogWrite(ACL, brightness); delay(30); Serial.println(brightness); }
delay(400); // this delay is importand to have not jump in the brightness of ACL when switching NAV-lights and strobe on and of. do not change this value.
goto Mainloop;
ACL_NAV_Strobe:;
counter1 = counter1+1;
analogWrite(brightness, 7); // brightness = 7; // for synchronisation, to have small remaining brightness at the lower end, like a downgoing bulb at the ACL
for (brightness <=7; brightness <252; brightness = brightness + brightness_increment){ analogWrite(ACL, brightness); delay(20); Serial.println(brightness); }
for (brightness <=253; brightness >=7; brightness = brightness - brightness_increment){ analogWrite(ACL, brightness); delay(30); Serial.println(brightness); }
// this two lines became necessary to synchronize the status of the ACL brightness when switching NAV lights and strobe on and off.
//without the repeat of that two lines, a small jump occures, that is visible. Took me time to find out:)
// the loop function Strobe runs 4 times ( 4 flashes ) and returns to Mainloop to check again the switch ( pulse ) status.
Strobe:;
counter2 = counter2+1;
digitalWrite(Strobelight, HIGH); // turn the LED on by making voltge HIG
delay(40); // wait for 50ms on time
digitalWrite(Strobelight, LOW); // turn the LED off by making the voltage LOW
delay(60); // wait for a second // Wait for 50ms off time
if ( counter2 == 4 ) { goto Mainloop; } // the 4 is the number of flashes in each cycle
{ goto Strobe; }
}