Author Topic: Knight rider Led array question  (Read 1741 times)

0 Members and 1 Guest are viewing this topic.

Offline DuncanSteelTopic starter

  • Contributor
  • Posts: 39
  • Country: ee
Knight rider Led array question
« on: September 11, 2017, 08:00:24 pm »
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?
« Last Edit: September 11, 2017, 08:02:34 pm by DuncanSteel »
 

Offline sokoloff

  • Super Contributor
  • ***
  • Posts: 1799
  • Country: us
Re: Knight rider Led array question
« Reply #1 on: September 11, 2017, 08:14:56 pm »
Use PWM at the gate of the MOSFET.
 

Offline DuncanSteelTopic starter

  • Contributor
  • Posts: 39
  • Country: ee
Re: Knight rider Led array question
« Reply #2 on: September 11, 2017, 08:21:36 pm »
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?
« Last Edit: September 11, 2017, 08:33:07 pm by DuncanSteel »
 

Offline sokoloff

  • Super Contributor
  • ***
  • Posts: 1799
  • Country: us
Re: Knight rider Led array question
« Reply #3 on: September 11, 2017, 11:25:16 pm »
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: [Select]
int intensity_of_led[8];

// 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[j] > i) {
            output |= 1;
        }
        if (j == 7)
            break;
        output <<= 1;
    }
    SHIFT_OUT(output);  // Send this to the shift register
    WAIT_FOR_TIMER(); // However you want to control the timer
}
 

Offline sokoloff

  • Super Contributor
  • ***
  • Posts: 1799
  • Country: us
Re: Knight rider Led array question
« Reply #4 on: September 11, 2017, 11:34:16 pm »
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.
 

Offline Richard Crowley

  • Super Contributor
  • ***
  • Posts: 4317
  • Country: us
  • KJ7YLK
Re: Knight rider Led array question
« Reply #5 on: September 11, 2017, 11:54:20 pm »
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/152



Or at least you can look at their open-source code:
http://wiki.evilmadscientist.com/Larson_Scanner
« Last Edit: September 11, 2017, 11:57:41 pm by Richard Crowley »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf