Knight rider Led array question - Page 1
Forum section: electronics / beginners

author: DuncanSteel
author_rank: Contributor
timestamp: September 11, 2017, 08:00:24 pm
content: Hi?I plan to build a knight lights and would like to know, what is the easiest way to do this?I know how to move the leds around, MCU & shift registers or multiplexors with mosfets at the LED VCC & GND pins should do it.Now whats the easiest way to control led intensity?Because I want the leds at the tail to be dimmer and move them around on top of it.1. Control somehow current of the leds, some kind of a variable current source? Do they exist?2. Use PWM at the gate of the mosfet?I wrote some ideas, are there more?

author: sokoloff
author_rank: Super Contributor
timestamp: September 11, 2017, 08:14:56 pm
content: Use PWM at the gate of the MOSFET.

author: DuncanSteel
author_rank: Contributor
timestamp: September 11, 2017, 08:21:36 pm
content: So how do you PWM two leds at the same time with different intensity?Whats the logic behind it?I understand how to PWM one led at the time.But with a shift register you cant do it, you need to use two separate pins right?

author: sokoloff
author_rank: Super Contributor
timestamp: September 11, 2017, 11:25:16 pm
content: You can do it with a shift register. Imagine that you want 256 steps of intensity. (Note that linear pulse width is not linear perceived brightness, but I'll ignore that here.) Imagine that you have 8 LEDs A, B, C...H(This code is untested and written off-hand in the browser. I don't even guarantee that it compiles... If it doesn't, I'll give you double your money back...)Code:int intensity_of_led;// Fill out that array as if by magic// Everytime through the (fast) timer loop:for (i=0; i < 256; i++) {output = 0;for (j = 0;; j++) {if (intensity_of_led > i) {output |= 1;}if (j == 7)break;output <<= 1;}SHIFT_OUT(output); // Send this to the shift registerWAIT_FOR_TIMER(); // However you want to control the timer}

author: sokoloff
author_rank: Super Contributor
timestamp: September 11, 2017, 11:34:16 pm
content: That code sets the low bit in the output accumulator iff the intensity is higher than the current position in the pulse width. (The total pulse frequency is 256 steps of i wide. The bit is on for intensity_of_led amount of that total time.)The output accumulator is then left shifted by 1 bit each time, so in the end, the accumulator ("output") contains the values for ABCDEFGH in bits 7 through 0.Shift out that output value and strobe the shift register and it presents bits ABCDEFGH in outputs ABCDEFGH.Then, wait the needed amount of time and go do the next cycle of i.On the bench, you can drive small LEDs right off the 74HC595 (though note that you might not be able to drive all LEDs 100% on without exceeding the max current on Vcc pin, so if you're going to breadboard it, only use 2 or 3 LEDs while you're first testing [where you're likely to test with "all on"]). Later, you can implement the Night Rider pattern directly on the 595, and even later drive MOSFETs off the 595 outputs (when you want to drive bigger LED loads).If the code doesn't work or you get stuck, let me know and I can put it into Arduino studio and see what I did wrong.

author: Richard Crowley
author_rank: Super Contributor
timestamp: September 11, 2017, 11:54:20 pm
content: That is called the "Larson Scanner" after Glen A. Larson who used the effect on both the Battlestar Gallactica and Knight Rider TV series he produced.For $12 you can buy the complete kit from EvilMadScientist.https://shop.evilmadscientist.com/productsmenu/152Or at least you can look at their open-source code:http://wiki.evilmadscientist.com/Larson_Scanner