Edit – I’m adding the code into this post. Initially it was on pastebin.
This is my first program that I’ve written from scratch, so I apologize if it’s coded poorly or hard to read.
I’m using an Arduino Uno.
I’m working on a circuit that will have an RF receiver and a 4-button remote control. It’s to control a metal sculpture of a dragon that will have glowing eyes and breathe fire. When the “A” button on the remote is pressed, the Arduino will trigger the fire sequence.
There are 3 outputs that I’m using:
a) LEDs in the eyes.
b) Electric sparking igniter
c) Solenoid valve that releases propane
Fire sequence when the A button is pressed is supposed to go like this:
- All outputs are shut off
- Sparking igniter turns on
- The LEDs in the eyes gradually increase in brightness
- Once at full brightness, the propane is released and the dragon builds fire
I built a test circuit for dubugging that instead of using actual solenoids or igniters, I just use LEDs instead.
What I find is that when I turn the arduino on, the first time I do a “fire sequence” it works perfectly.
The second time I do it, this is what happens:
- All outputs are shut off (OK)
- Sparking igniter turns on (OK)
- The LEDs in the eyes flash on and off a few times very quickly, then gradually increase in brightness the way they are supposed to (problem)
- Once at full brightness, the propane is released and the dragon builds fire (OK)
The fire sequence function starts at line 181. The behavior suggests to me that the x variable in the for loop in that function persists even after the fireSequence function executes, the program goes to loop, and then returns for the second time I call up the fire sequence. I had a friend look at the program and he thinks that is not the problem, but he hasn’t done a lot of programming for a few years and never used and Arduino, so I thought I’d check if anyone here had an idea.
Can anyone guess why the “LEDpin” output may be going high when it’s not supposed to?
Thank you!
dragon_fire.ino (6.76 KB)