I am trying to get a better understanding of writing my own (initial and very basic) code on the arduino. I am new to this and may use terminology wrong, feel free to correct me I am not offended by free learning
I am looking at the basic led fader (File-> Exmaples-> Basics-> Fade). I want to try making this work in a few different ways and then to understand this in reference to the 'environment' it is operating inside of.
Facts:
- Arduino-Knockoff Nano
- ground wired to cathode of 3 separate leds
- Pins 3, 5 and 9 each wired to the anode side of an LED+Resistor
Intended Result:
Change fade program to:
1.)fade the first led on brighter,
2.)then when the first led begins dimming to begin fading the second led on,
3.)when the second led has reached maximum brightness the first led will have just reached minimum (off) brightness, the first led remains off while the second led begins it's dimming cycle and the third led begins to increase it's brightness from off,
4.)When the third led is at maximum, the second led will now be off and the third led will begin dimming, triggering the increasing brightness on the first led and starting the process all over again.
I realize I have not written code for the third led, I have gotten the second led to address directly by simply operating both leds together, so I can use other pins successfully but I'm not creating separate processes/events and making one the trigger for the next. I suspect that I will use whatever this process, in order to allow the third led dimming point of time to coincide with (or trigger) the first led starting up again and tieing the code back into itself.
I believe that I am posting in the proper fashion and that this question has not been addressed. What I am asking for is pretty basic, probably so basic is why is has not been addressed
I have reviewed the following two links:
http://forum.arduino.cc/index.php?topic=97455.0
("read this before posting a programming question")
which references: http://forum.arduino.cc/index.php/topic,148850.0.html
("how to use this forum" under "Installation and Troubleshooting")
These are just my ideas on how this can be possibly accomplished but may or may not apply
If my first LED is LED9 and my second led is LED3; Can I make one led reaching maximum (255) brightness become a trigger, a sort of:
{
if (brightness == 255) {
int led2 = 3
int brightness = 0 // how bright the LED is
int fadeAmount = 5 // How much to fade the led by each cycle
pinMode(led2, OUTPUT); // declare pin 3 to be an output:
analogWrite(led2, brightness); // set the brightness of pin 3
brightness = brightness + fadeAmount; //(dang, which led am i addressing with this statement?) // change the brightness for next time through the loop:
if (brightness == 255) {
fadeAmount = -fadeAmount ;
// reverse the direction of the fading at the end of the Brightening cycle (0-255 but do not reverse when reaching 255-0, simply stay off until code from another led cycle triggers this process to start once more).
delay(30);
// wait for 30 milliseconds to see the dimming effect
Perhaps there is a way to run all 3 leds independently and then put a delay on each one so they cycle like I described but not actually having code interconnected; of course I must understand the timing of the environment, this has been explained in terms of clock cycles but I'm not clear esp enough for 'real world timing' like this. Also are there interrupts the arduino simply experiences as a matter of normal operation that would cause delays in these cycles to build up and malign them (heck would running another cycle for a second and third led be the very cause of the random interrupts)?
I really prefer to learn how to make the code actually link, of course by looking at my code above some of you will be able to spot some pretty basic mistakes (I get the first led to light up from off, then to light up from off, and so on, it never dims back down from Bright and nothing else actually triggers)