1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
| // =============== Voyager LED sequence =============== //
// Note: Total duration per fade: (miliseconds) = maxPWM / fadeIncrement * fadeInterval
// =============== Configuration =============== //
// Configuration strobes
const int pin_Strobe[] = {7, 8, 8, 7}; // Strobe LED pins are triggered in this sequence after the period in array_Strobe has passed
unsigned long array_Strobe[] = {3250, 50, 150, 50}; // Array {OFF, ON, etc.}. How in setup the leds are initalized determines the first state (LOW = off, HIGH = on)
const byte interval_Strobe = sizeof(array_Strobe) / sizeof(unsigned long); // Tracker for how many intervals have past
byte civ_Strobe = 0; // Current Interval Value counter
unsigned long pmillis_Strobe = 0; // Millis start value
// Configuration fade: all arrays are only nessessary for fading leds. But they are all filled so a pwm led can be on each position in the sequence.
// Lights(indexnrs): Cabin(0), Navigation(1), strobes(2), Deflector(3), Impulse(4), Nacelles(5), Floodlight(6), Torpedo(7)
// { 0, 1, 2, *3, *4, *5, *6, 7 } // Array index number (* = PWM function in use)
const int LED[8] = { 6, 12, 7, 11, 10, 9, 3, 5 }; // Pin nrs
const int maxPWM[8] = { 255, 255, 255, 255, 255, 255, 255, 255 }; // Max brightness
const int Time[8] = { 1000, 1000, 4000, 5500, 7000, 8500, 10500,10500 }; // Start time for led to go on (counted from time = 0)
int fadeValue[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; // Start fade higher then 0 (from start timeline)
int fadeInterval[8] = { 50, 50, 50, 50, 50, 50, 50, 50 }; // How fast to increment?
byte fadeIncrement[8] = { 5, 5, 5, 2, 3, 3, 3, 5 }; // How smooth to fade? Lower = smoother.
unsigned long pmillis_Fade[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; // millis() timing Variable for fading
unsigned long pmillis_Seq = 0; // millis() timing Variable for startsequence
byte fadeDirection = 0; // Variable for fade Direction (0 = up, 1 = down)
// =============== SETUP =============== //
void setup()
{
for (int y=0; y < 8; y++) { // Look up all led pins in array,
pinMode(LED[y], OUTPUT); } // and set all LED's in the array to output
digitalWrite(8, LOW); // Write initial state of strobe light 1
digitalWrite(LED[2], LOW); // Write initial state of strobe light 2
for (int x=3; x < 7; x++) { // Look up all PWM led pins in array (only possible if next to each other in the array),
analogWrite(LED[x], fadeValue[x]); } // and write initial state of fade leds
}
// =============== FUNCTIONS =============== //
void Strobe(unsigned long now) { // Strobes function
if (now - pmillis_Strobe >= array_Strobe[civ_Strobe]) { // If the time interval has elapsed,
civ_Strobe = civ_Strobe + 1; // select the next interval in the list,
if (civ_Strobe >= interval_Strobe) { // if all intervals in array have been past,
civ_Strobe = 0; } // reset the array to start,
digitalWrite(pin_Strobe[civ_Strobe], not digitalRead(pin_Strobe[civ_Strobe])); // change state of the LED each next interval step,
pmillis_Strobe = now; } // save the time of change
}
void Fade(unsigned long now, int x) { // Fade function
if (now - pmillis_Fade[x] >= fadeInterval[x]) { // If the time interval has elapsed,
fadeValue[x] = fadeValue[x] + fadeIncrement[x]; // select the next interval in the list,
if (fadeValue[x] >= maxPWM[x]) { // if all intervals have been past,
fadeValue[x] = maxPWM[x]; } // end fade and keep it max,
analogWrite(LED[x], fadeValue[x]); // write brightness to led,
pmillis_Fade[x] = now; } // save the time of change.
}
// =============== LOOP =============== //
void loop()
{
unsigned long now = millis(); // Get current value of millisecond counter for functions
// Start startsequence
for (int y=0; y < 8; y++) { // For each index in the array
if (now - pmillis_Seq > Time[y]) { // If time in array has past (counted from start timeline),
if ( y==3 || y==4 || y==5 || y==6 ) { // if index is a pwm led,
Fade(now, y); } // call fade function with current millis
else if ( y == 2 ) { // Else if index is the strobes,
Strobe(now); } // call the strobes function
else { // If not pwm led of strobe,
digitalWrite(LED[y], HIGH);} // just switch on led
}
}
Strobe(now); // Update strobes
} |