LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

blink(toggle) pwm controlled led on arduino

Hello

I want to blink multiple LEDs Which are PWM controlled at the same time to change the intensity. I am able to do Both blinking and PWM control seperatly but I am unable to make them work togeather.

Secondly in the blinking program the LEDs are blinking and Continuously When I Stop the program some Leds Which are on At That Particular Moment doesnot get off. How can I solve this issue?

I am attaching Both blinking and PWM control codes

Download All
0 Kudos
Message 1 of 14
(4,780 Views)

The "blinking" question is easy (I was able to "guess" the error you were making without even looking at the code).  You are turning the LEDs on and off, but are chosing to exit the loop without checking (or setting) the final LED state.  When you exit the While loop, check the output from the Shift Register, and if you just turned the LED on, add a little extra code to turn it back off.

 

Bob Schor

0 Kudos
Message 2 of 14
(4,753 Views)

One more thing, I also want to sequentially move from one LED to other, for that I am using case structure for each blinking pin block but that is also not working

😞

0 Kudos
Message 3 of 14
(4,746 Views)

Is it possible to use blinking with pwm control? And also to sequentially control all 12 Leds even?

0 Kudos
Message 4 of 14
(4,741 Views)

A comment -- whenever a Block Diagram is as repetetive as yours, there is a strong urge to recommend using a single For loop to cycle through all of the choices and to use Arrays.  In your Blinking routine, you might not be able to use a For loop if you want the lights to blink at independent rates (because you want the While loops to run independently, in parallel), but you might consider having a "neater" Front Panel by replacing your many Stop buttons, messily scattered over the Front Panel making it difficult to tell which button controls which LED with an Array of Stop Buttons, which at least forces them into a horizontal or vertical "array" (you could also make a 2-by-6 or 4-by-3 array) which is much neater and possibly has a more "natural" positional association with the blinking LEDs.

 

BS

0 Kudos
Message 5 of 14
(4,739 Views)

I don't know what you mean by "move from one LED to another".  Can you describe, on a time line, what you want to happen?  Do you want LED 1 to come on for N milliseconds (and then go off), LED 2 to come on at N milliseconds (or N+M), stay on for N ms, then go off, and so on until you reach LED 12, after which the cycle repeats?

 

If something like this is the case, then my previous comment about using a single For loop and arrays "comes alive" again, as now the 12 loops are not independent, but are tightly coupled and are really part of a single pattern.  Some things to consider when designing this -- consider whether you want a single Stop button to stop the successive flashing, what light state you want when stopped, etc.  

 

BS

0 Kudos
Message 6 of 14
(4,733 Views)

I think I answered the "sequentially control all LEDs" in my previous post.  As to whether you can combine PWM and On-Off behavior, I think that's more a function of what Arduino allows (but I'm not certain of that, as I don't have that much Arduino experience).

 

BS

0 Kudos
Message 7 of 14
(4,725 Views)

I want to toggle i.e blink a LED for certain time then move to other LED and do the same

and for repetiton of the blocks, they are connected to different pins of arduino so to turn all of them on or to blink all at the same time i need to address all pins of arduino seperatly

0 Kudos
Message 8 of 14
(4,717 Views)

@strager_smz wrote:

I want to toggle i.e blink a LED for certain time then move to other LED and do the same

and for repetiton of the blocks, they are connected to different pins of arduino so to turn all of them on or to blink all at the same time i need to address all pins of arduino seperatly


So my For loop method would work fine.  Note that the For loop has an index ("i") that starts at 0 and increments by 1 for each loop.  Within the For loop, you need to "map" i into the pin number of the Arduino.  If you are really lucky, there may be an input parameter for this that runs from 0 to 11, so you just wire "i" into it.  Maybe it runs from 1 to 12 -- wire "i" into it, but put an Increment function between "i" and the Arduino input.  In any case, there's some way to associate the Arduino input with the For loop index, right?  Even a really tiny Case structure with "23, 14, 35, 42, ..." as the (ridiculous) sequential Arduino ports you need to use.

 

Each time through the For loop, the code inside the loop with address a particular Arduino LED.  If you want the LED to blink 3 times, you'd put, inside this For loop, another For loop with 3 wired to N (or perhaps 6 if you want to count "on" and "off" states separately", bring the LED Index in from the outer For loop, and let the inner one handle the timing (put your Wait function here) and toggling of the LED (the shift register that goes True/False to turn the LED On/Off goes here, initialized however you want when you enter the For loop).

 

Have you noticed how, in response to some of my questions, you've better derined the scope of your program, and with the scope better understood, simple solutions begin to suggest themselves?  There is an important Lesson and Principle here ...

 

Bob Schor
  

0 Kudos
Message 9 of 14
(4,691 Views)

Actually I have to address different pins of arduino which are not in sequence

I have tried this approach, please have a look and tell me some better way how to improve

0 Kudos
Message 10 of 14
(4,668 Views)