Go Down

Topic: Starting and stopping an LED chase with a pushbutton (Read 7339 times) previous topic - next topic

Hackscribble

Hi Shawn

Looking into the library, the loop() function in the library has been written on the assumption that it gets called each time round the main program loop (i.e. at a frequency higher than the frequency at which the chase sequence moves from one step to the next).

In your program, you want to pause the sequence, so this is not happening.

One way to prove whether this is the cause of the problem you are seeing is as follows ...

1.  Add a global variable

Code: [Select]
boolean chaseOn = false;

2.  In your if statements at the two places where you currently have nacelleChase.loop();, remove these statements and replace with

Code: [Select]
chaseOn = true;

3.  In your if statement where you set all the LEDs low, add this

Code: [Select]
chaseOn = false;

4.  Right at the end of your main program loop, add just one

Code: [Select]
nacelleChase.loop();

5.  Near the top of your program where the advance() function is declared, change digitalWrite(nextPin, HIGH); to this

Code: [Select]
if (chaseOn)
{
    digitalWrite(nextPin, HIGH);
}


What this should do is keep the chase constantly updated but (thanks to item 5) only switch on the LEDs when one or other of the switches is closed. 

Regards

Ray
Hackscribble.  Writing about making things
hackscribble@outlook.com

WShawn

Hi Ray:

Once again, my sincere thanks for all the help you're giving me.

I'll play around with the code as soon as I can.  I'll be at the convention the next few days, then slammed with client work.

FYI, I'm currently using 150 ohm-ish resistors on this breadboard.  Right now they're not all the same value; they're a mixture of whatever I had lying around.  In my current PKE prop I'm using 7 NPN 3904 transistors to switch on each group of three LEDs (one in each wing and one on the readout screen).  Each group shares a common V+ lead, and I used a single 220 ohm resistor in each common lead.  Since only one LED in each group is firing at any time this seems to have worked, even though it would probably be better to have a resistor on each LED.  I'm just trying to save space in the prop.

Take care.

Shawn

WShawn

Where were we?

Oh yeah, I went to the 2014 Rose City Comic Con, then had a bunch of client work, then used a lot of my free time to make molds of my PKE prop shells to make resin casts, only to decide to use my master for the final prop.  Then I went to the 2015 RCCC.

So I finally had a chance to integrate this new code, and lo and behold it works.  Hooray for Zoidberg!!

Thanks for all of your help with this, Ray.

Now I need to play around with replacing the physical buttons with resistive touch switches.

Cheers.

Shawn

Go Up