Go Down

Topic: Aircraft lighting trouble ... (Read 393 times) previous topic - next topic

JohnnyDoe

Sep 19, 2017, 04:18 am Last Edit: Sep 19, 2017, 04:32 am by JohnnyDoe
Hello,

I'm working on an aircraft lighting scheme using LEDs and Arduino. I cannot figure out how to get parts of the sequence to initiate at the same time. I know the code is read and executed from the top down, but am stuck.

my code -

Code: [Select]


void setup() {
  // initialize digital pins as output  
  pinMode(3, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(9, OUTPUT);

}

void wingRedGrn(){
  digitalWrite(9, HIGH);
  delay(50);
  digitalWrite(9, LOW);
  delay(50);
  digitalWrite(9, HIGH);
  delay(50);
  digitalWrite(9, LOW);
  delay(850);
}

void tailWht(){
  digitalWrite(3, HIGH);
  delay(100);
  digitalWrite(3, LOW);
  delay(100);
  digitalWrite(3, HIGH);
  delay(100);
  digitalWrite(3, LOW);
  delay(900);
}

void beaconRed(){
  delay(500);
  digitalWrite(5, HIGH);
  delay(100);
  digitalWrite(5, LOW);
  delay(1000);
}

  
// the loop
void loop() {
  tailWht();
  wingRedGrn();
  beaconRed();

}



and here's the pattern I'm trying to duplicate:

Wawa

Delay() is blocking code.
Look at the "BlinkWithoutDelay" sketch in the examples of the IDE.
There timing is done without the use of delay().
Leo..

kenwood120s

Here's OP's pic:



Was going to say about delay() but Wawa got in first.

(If this is for a real aircraft, be aware that according to Atmel's docs, the processors aren't rated for aeronautical use without written permission.)

[gumby]I've got my head stuck in the cupboard[/gumby]

JohnnyDoe

Delay() is blocking code.
Look at the "BlinkWithoutDelay" sketch in the examples of the IDE.
There timing is done without the use of delay().
Leo..
Thank you, I will try out those examples and return with something proper. Fingers crossed.



Was going to say about delay() but Wawa got in first.

(If this is for a real aircraft, be aware that according to Atmel's docs, the processors aren't rated for aeronautical use without written permission.)
Thanks for adding the picture, couldn't figure out how to add so late at night ...

Not for a "real" aircraft per se ... but ... maybe a HAB or U1 project ... or for the step-son pilot/heli mechanic ...

JohnnyDoe

Just thought I would share what I've found and this will be the "classy" route I will undertake:

https://learn.adafruit.com/multi-tasking-the-arduino-part-1?view=all#a-classy-solution

snippet from this write-up:
https://learn.adafruit.com/multi-tasking-the-arduino-part-1?view=all


kenwood120s

Of course there's a slight wrinkle in the double flash of the strobes, but I daresay you'll iron that out.

[gumby]I've got my head stuck in the cupboard[/gumby]

PaulRB

#6
Sep 20, 2017, 07:39 am Last Edit: Sep 20, 2017, 08:20 am by PaulRB
You don't need to learn "multi-tasking" or Object Oriented Programming to make this work. There really is no multi-tasking going on here, just a single linear task. The problem is you are thinking about each led in isolation. Instead, think of this more like the music roll that controls when the notes start and stop in a fairground organ. Use your diagram. Start at the left side and work your way to the right. Switch LEDs on and off in sequence, using delay() to space out the events in time. You only need to get to 1 second, the whole pattern just repeats after that.

PaulRB

#7
Sep 20, 2017, 03:09 pm Last Edit: Sep 20, 2017, 03:11 pm by PaulRB
Try this:
Code: [Select]


void setup() {
  // initialize digital pins as output 
  pinMode(3, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(9, OUTPUT);

}
 
// the loop
void loop() {
  digitalWrite(9, HIGH);
  digitalWrite(3, HIGH);
  delay(50);
  digitalWrite(9, LOW);
  delay(50);
  digitalWrite(9, HIGH);
  digitalWrite(3, LOW);
  delay(50);
  digitalWrite(9, LOW);
  delay(350);
  digitalWrite(5, HIGH);
  delay(100);
  digitalWrite(5, LOW);
  delay(490);
}

JohnnyDoe

#8
Sep 21, 2017, 04:38 am Last Edit: Sep 21, 2017, 04:53 am by JohnnyDoe
Try this:
Bloody easy code that was ... brilliant ...

I broke out the Arduino Cookbook and was working out millis() schemes and tried setting up a few libraries with repeat count and my next stop was going to try TimedActions ...

you were right, I was over complicating the scheme, breaking it down in chunks instead of going with the flow of time ... sometimes I wonder where my noggin is ...

Airbus A380 with Anti-Collision Lights

kenwood120s

Bloody easy code that was ... brilliant ...
It is an elegant solution, but just be aware before you cast it in stone that if you want your sketch to do anything else (I say if), then that solution (perfect as it is for doing only what it does) will block you. (It's blink, not blinkwithoutdelay.)
[gumby]I've got my head stuck in the cupboard[/gumby]

PaulRB

What Kenwood says it's of course absolutely true. As soon as you need to, say, detect a button press while the light sequence is running, those delay()s cause problems.

But if that's all the circuit will ever do, you could save your Uno (or what ever you have) and use attiny45 or 85.

Go Up