using POV to do Knight Rider effect?

by handsomeryan on Mon Sep 10, 2007 11:38 am

Would this circuit be usable for making a Knight Rider effect such as pictured below?

Image

Of course there would only be 8 lights and i do not know how bright to expect them to be. But if you added wires to space the LED's appart slightly and made some type of housing to evenly disperse the light, is this do-able using the MiniPOV kit? I'm trying to immagine how quickly the lights 'cycle'.

Thanks,
-Ryan
Ready your breakfast and eat hearty, for tonight, we dine in hell
handsomeryan
 
Posts: 12
Joined: Mon Sep 10, 2007 11:27 am

by adafruit on Mon Sep 10, 2007 12:21 pm

sure you can do this, just use the testled.c code as a template and go from there!
User avatar
adafruit
 
Posts: 11663
Joined: Thu Apr 06, 2006 3:21 pm
Location: nyc

by handsomeryan on Mon Sep 10, 2007 12:37 pm

What a quick response!

I ordered a kit this weekend and I have not decided what to do with it yet. i just saw it @ Make! and thought "That's cool, I want one!". Maybe i'll try for an 'LED scanner' or maybe I'll built it conventionally and order more kits for other projects.

I was really intimidated about trying my hand at 'building' a circuit but it looks like you have streamlined the process to make it easy for a beginner. Also there is so much great info here to help me figure out WTF i'm doing. Thanks!
Ready your breakfast and eat hearty, for tonight, we dine in hell
handsomeryan
 
Posts: 12
Joined: Mon Sep 10, 2007 11:27 am

by Spacehead on Wed Sep 26, 2007 10:34 am

I built the POV3 kit and loaded a few different programs into it. I can't seem re save any edited programs. I would also like to get the testled.c code program back on it but can not seem to find it any where. I assume that my in abillity to save edited programs is due to my not using the right editor(notepad?) or being un able to save it as a file type(.c?) But mostly because this is all very Greek to me! I am trying and learning but the curve seems to be high at the moment.
Please advise
Thank you
User avatar
Spacehead
 
Posts: 2
Joined: Wed Sep 26, 2007 10:25 am
Location: Midwest

Improved Cylon/KITT scanner program

by darus67 on Sat Oct 20, 2007 1:50 am

I whipped up an improved scanning LED program tonight. It uses PWM to fade out the trailing LED.

Here's the code. Its even heavily commented so someone other than ME might stand a chance of understanding it.
Enjoy

Code: Select all | TOGGLE FULL SIZE
/**************************************************************************
  This program will cause the LEDs on the MiniPOV3 to scan back & forth,
  with the trailing LED fading out, similar to the old school Cylons
  from the original Battlestar Galactica or KITT from Knight Rider

  This code is released into the public domain, with no warranty.
  Do with it what you will, but harm none.
  If it breaks, you get to keep all the pieces.

  darus67
  20 October 2007
**************************************************************************/

#include <avr/io.h>  // this contains all the IO port definitions

#define FADE_RATE 12 // the larger this value, the slower
                     // the LED will fade

#define INITIAL_WIDTH 128 // the starting value of the PWM pulse
                          // this is about 50% pulse width

void fade(char bit){
/**************************************************************************
  Use pulse width modulation to cause LEDs on Port B to fade out
  LEDs corresponding to high bits in 'bit' will fade out
**************************************************************************/
  unsigned char rate = FADE_RATE;
  unsigned char pulse_width = INITIAL_WIDTH;
  unsigned char count;

  while(pulse_width){   // as long as pulse_width is non-zero
                        // loop through the PWM routine

    PORTB |= bit;       // turn on the LED

    for(count=0; count<pulse_width; count++){   // count up to pulse_width

                  // Do nothing for 1 clock cycle
       asm("NOP");// If this is not here, the compiler may
                  // remove the empty delay loop
    }

    PORTB &= ~bit;       // turn off the LED

    for(; count; count++){ // count starts where it left off
                           // and continues up until it rolls over
                           // from 255 to 0

      asm("NOP");       // Do nothing for 1 clock
    }

    if(!rate--){        // Decrement rate. If it hits zero then
      pulse_width--;    // decrement pulse_width and
      rate = FADE_RATE; // reset rate
                        // When pulse_width hits zero, the while loop
    }                   // terminates and the function returns

  } // end while

} // end fade


int main(void) {

  char b;       // a byte to keep track of the lit LED

  DDRB  = 0xFF;    // Set Port B to all outputs

  while(1){     // loop forever

    // scan from right to left, with the trailing LED fading out.
    for(b=0x02; b; b<<=1){  // Instead of incrementing, b gets shifted left.
                            // When the 1 bit shifts off the left side
                            // b == 0 and the loop terminates

      PORTB = b;  // turn on the LED

      fade(b>>1); // call fade to fade out the LED to the right of
                  // the currently lit one
    }

    // scan from left to right, with the trailing LED fading out
    for(b=0x40; b; b>>=1){ // We're shifting b right instead of left this time

      PORTB = b;  // turn on the LED

      fade(b<<1); // fade the LED to the left of the lit one
    }

  } // end while

} // end main
"He's just this guy. You know?"
User avatar
darus67
 
Posts: 246
Joined: Wed Sep 26, 2007 9:25 pm
Location: Minnesota, USA

by Spacehead on Sun Oct 21, 2007 11:15 pm

That's awesome but... how do I save it so I can load it on my POV?
I tried pasting it to notepad and saving in the POV directory but keep getting "Error1" states no such file or directory when I try loading it with the averdude.
I am missing something but what?
User avatar
Spacehead
 
Posts: 2
Joined: Wed Sep 26, 2007 10:25 am
Location: Midwest

by darus67 on Mon Oct 22, 2007 12:43 am

You should be able to copy and paste it into notepad and then save as cylon.c

Next you'll have to edit your Makefile

Look for the section that looks like this:

program-minipov: minipov.hex
program-all_leds: all_leds.hex
program-test_leds: test_leds.hex
program-alt_leds: alt_leds.hex
program-mypov: mypov.hex
program-test_sensor: test_sensor.hex

now add a line that says
program-cylon: cylon.hex
and save the Makefile

Now you should be able to do:
make program-cylon

and it will compile the program and load it onto your MiniPOV
"He's just this guy. You know?"
User avatar
darus67
 
Posts: 246
Joined: Wed Sep 26, 2007 9:25 pm
Location: Minnesota, USA

by magician13134 on Tue Oct 23, 2007 5:32 am

Wow, very, VERY cool, great job with the PWM, I was working on that for awhile, but NEVER got anywhere near that good! I LOVE it!
User avatar
magician13134
 
Posts: 1119
Joined: Wed Jun 13, 2007 8:17 am
Location: Ann Arbor

by darus67 on Tue Oct 23, 2007 11:42 pm

It would be even better if I could have 2 LEDs fading out and 1 full on.
That would be closer to the original which appears to have 1 full on and 3 fading. It also has a dozen or more light segments, too.

Right now I have 1 full on and 1 fading.
"He's just this guy. You know?"
User avatar
darus67
 
Posts: 246
Joined: Wed Sep 26, 2007 9:25 pm
Location: Minnesota, USA

Re: using POV to do Knight Rider effect?

by Jaydmdigital on Sat Nov 21, 2009 5:40 pm

Modified the posted code for two trailing LEDs. The second one is set to be 1/16th of the first trailing LED. I am using superbright LEDs so this worked for me, but might be too high for other LEDs.

Jay
Code: Select all | TOGGLE FULL SIZE
/**************************************************************************
  This program will cause the LEDs on the MiniPOV3 to scan back & forth,
  with the trailing LED fading out, similar to the old school Cylons
  from the original Battlestar Galactica or KITT from Knight Rider

  This code is released into the public domain, with no warranty.
  Do with it what you will, but harm none.
  If it breaks, you get to keep all the pieces.

  darus67
  20 October 2007
**************************************************************************/

#include <avr/io.h>  // this contains all the IO port definitions

#define FADE_RATE 12 // the larger this value, the slower
                     // the LED will fade

#define INITIAL_WIDTH 64 // the starting value of the PWM pulse
                          // this is about 50% pulse width

void fade(char bit1, char bit2){
/**************************************************************************
  Use pulse width modulation to cause LEDs on Port B to fade out
  LEDs corresponding to high bits in bits 'bit1' and 'bit2' will fade out
**************************************************************************/
  unsigned char rate = FADE_RATE;
  unsigned char pulse_width = INITIAL_WIDTH;
  unsigned char count;

  while(pulse_width){   // as long as pulse_width is non-zero
                        // loop through the PWM routine

    PORTB |= bit1|bit2;       // turn on the LED

    for(count=0; count<(pulse_width/16); count++){   // count up to pulse_width for the second LED is 1/16th the first one
                  // Do nothing for 1 clock cycle
       asm("NOP");// If this is not here, the compiler may
                  // remove the empty delay loop
    }

    PORTB &= ~bit2;       // turn off the second LED
   
    for(count=0; count<pulse_width; count++){   // count up to pulse_width for the first LED
                  // Do nothing for 1 clock cycle
       asm("NOP");// If this is not here, the compiler may
                  // remove the empty delay loop
    }

    PORTB &= ~bit1;       // turn off the first LED

    for(; count; count++){ // count starts where it left off
                           // and continues up until it rolls over
                           // from 255 to 0

      asm("NOP");       // Do nothing for 1 clock
    }

    if(!rate--){        // Decrement rate. If it hits zero then
      pulse_width--;    // decrement pulse_width and
      rate = FADE_RATE; // reset rate
                        // When pulse_width hits zero, the while loop
    }                   // terminates and the function returns

  } // end while

} // end fade


int main(void) {

  char b;       // a byte to keep track of the lit LED

  DDRB  = 0xFF;    // Set Port B to all outputs

  while(1){     // loop forever

    // scan from right to left, with the trailing LED fading out.
    for(b=0x02; b; b<<=1){  // Instead of incrementing, b gets shifted left.
                            // When the 1 bit shifts off the left side
                            // b == 0 and the loop terminates

      PORTB = b;  // turn on the LED

      fade(b>>1,b>>2); // call fade to fade out the two LEDs to the right of
                  // the currently lit one
    }

    // scan from left to right, with the trailing LED fading out
    for(b=0x40; b; b>>=1){ // We're shifting b right instead of left this time

      PORTB = b;  // turn on the LED

      fade(b<<1,b<<2); // fade the two LEDs to the left of the lit one
    }

  } // end while

} // end main
Jaydmdigital
 
Posts: 5
Joined: Sat Nov 21, 2009 5:38 pm

Re: using POV to do Knight Rider effect?

by jasonx on Sat Feb 27, 2010 7:39 pm

How easy would it be to speed the left to right scan of the led's in this firmware ?

Edit sorry I figured it out just after I asked :oops:

#define INITIAL_WIDTH 64 // the starting value of the PWM pulse
// this is about 50% pulse width
User avatar
jasonx
 
Posts: 168
Joined: Wed Jan 16, 2008 4:41 pm
Location: england

Re: using POV to do Knight Rider effect?

by tcharron on Sun Feb 28, 2010 9:15 am

tcharron
 
Posts: 48
Joined: Tue Oct 13, 2009 6:15 pm

Re: using POV to do Knight Rider effect?

by Tones on Wed Jun 22, 2011 4:06 am

I can't figure out how to get this code to compile.

I've used darus67's advice from above:
1. Copied the cylon code into a new cylon.c file
2. Added a new line to the Makefile: "program-cylon: cylon.hex"

However, when I try running "make program-cylon", I get an error: "make: *** No rule to make target `cylon'. Stop."

I don't understand AVR programming well enough to know what's going wrong here. Any advice would be appreciated!
Tones
 
Posts: 16
Joined: Fri Dec 12, 2008 4:17 am

Re: using POV to do Knight Rider effect?

by adafruit on Wed Jun 22, 2011 1:04 pm

just rename the cylon.c code to one of the existing code examples, that way you dont have to worry about the makefile
User avatar
adafruit
 
Posts: 11663
Joined: Thu Apr 06, 2006 3:21 pm
Location: nyc

Re: using POV to do Knight Rider effect?

by Tones on Wed Jun 22, 2011 2:30 pm

That did it, thanks!

But I'd like to understand what's happening here in a little more depth. Why is it that "program-eyebeam: eyebeam.hex" works, but "program-cylon:cylon.hex" fails?
Tones
 
Posts: 16
Joined: Fri Dec 12, 2008 4:17 am