Go Down

Topic: 74HC595 - psudo PWM - and KITT Scanner (Read 705 times) previous topic - next topic

spycatcher2k

I recieved my 74HC595s 2 days ago, and wanted to make a simple test circuit, so wired up the chip as shown elsewhere on this site, but was informed that PWM fading was not easily possible.  :'(
So I sat down and worked this out - See my code. Its fairly straight forward, if a little 'messy' (I could use bit shifting for the animation, but this works for me just now).
Code: [Select]
//**************************************************************//
//  Name    : Kitt_V2                                
//  Author  : Drew Anderson  
//  Date    : 22/04/2010    
//  Modified:                                  
//  Version : 2.0                                            
//  Notes   : Code for using a stop Shift Register
//          : with custom bitmaps                          
//****************************************************************

//Pin connected to ST_CP of stop
int latchPin = 8;
//Pin connected to SH_CP of stop
int clockPin = 12;
////Pin connected to DS of stop
int dataPin = 11;


 int startdly(150);
 int strobedly(120);
 
  // Out to 74HC595 (Serial TO Parallel OUT)
  //
 
   void stopout(int numberToDisplay)
   {
   // take the latchPin low so
   // the LEDs don't change while you're sending in bits:
   // digitalWrite(latchPin, LOW);
   // shift out the bits:
   shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay);  

   //take the latch pin high so the LEDs will light up:
   digitalWrite(latchPin, LOW);
   digitalWrite(latchPin, HIGH);
   }

void setup() {


 //set pins to output so you can control the shift register
 pinMode(latchPin, OUTPUT);
 pinMode(clockPin, OUTPUT);
 pinMode(dataPin, OUTPUT);

 //Startup Animation V1.0
 
 //Lets Clear the LEDs - just incase the 74HC595 'remembers' its last state after restart.
 stopout(B00000000);
 delay(500);
 
 //Fade up Startup Routine
 for(int x=0;x<20;x++)
 {
   for(int y=0;y<4;y++)
   {
   stopout(B11111111);
   delay(x);
   stopout(B00000000);
   delay(19-x);
 }
 }
 
 //Fade Down Startup Routine
   for(int x=0;x<10;x++)
 {
   for(int y=0;y<4;y++)
   {
   stopout(B11111111);
   delay(9-x);
   stopout(B00000000);
   delay(x);
 }
 }
 
 //duel fade
 
 for(int z=0;z<5;z++)
 {
   for(int x=0;x<10;x++)
 {
   for(int y=0;y<4;y++)
   {
   stopout(B11011011);
   delay(9-x);
   stopout(B00100100);
   delay(x);
 }
 }
     for(int x=0;x<10;x++)
 {
   for(int y=0;y<4;y++)
   {
   stopout(B00100100);
   delay(9-x);
   stopout(B11011011);
   delay(x);
 }
 }
 }


 //Lets fade middle 4, outer 4 LEDS are static
 for(int z=0;z<5;z++)
 {
   for(int x=0;x<10;x++)
 {
   for(int y=0;y<4;y++)
   {
   stopout(B11000011);
   delay(9-x);
   stopout(B11111111);
   delay(x);
 }
 }
     for(int x=0;x<10;x++)
 {
   for(int y=0;y<4;y++)
   {
   stopout(B11111111);
   delay(9-x);
   stopout(B11000011);
   delay(x);
 }
 }
 }

 //Binary Number to output
 //stopout(B********);  where ********* is Binary sprite info
 stopout(B00011000);
 delay(startdly);
 stopout(B00111100);
 delay(startdly);
 stopout(B01111110);
 delay(startdly);
 stopout(B11111111);
 delay(startdly);
 stopout(B11100111);
 delay(startdly);
 stopout(B11000011);
 delay(startdly);
 stopout(B10000001);
 delay(startdly);
 stopout(B00000000);
 delay(startdly);
 stopout(B00011000);
 delay(startdly);
 stopout(B00100100);
 delay(startdly);
 stopout(B01000010);
 delay(startdly);
 stopout(B10000001);
 delay(startdly);
 stopout(B01000010);
 delay(startdly);
 stopout(B00100100);
 delay(startdly);
 stopout(B00011000);
 delay(startdly);
 stopout(B00000000);
 delay(startdly);
 
 
 
 
 
}

void loop() {

   stopout(B10000000);
   delay(strobedly);
   stopout(B01000000);
   delay(strobedly);
   stopout(B00100000);
   delay(strobedly);
   stopout(B00010000);
   delay(strobedly);
   stopout(B00001000);
   delay(strobedly);
   stopout(B00000100);
   delay(strobedly);
   stopout(B00000010);
   delay(strobedly);
   stopout(B00000001);
   delay(strobedly);
   stopout(B00000010);
   delay(strobedly);
   stopout(B00000100);
   delay(strobedly);
   stopout(B00001000);
   delay(strobedly);
   stopout(B00010000);
   delay(strobedly);
   stopout(B00100000);
   delay(strobedly);
   stopout(B01000000);
   delay(strobedly);
   
 

 
}


Please leave a reply if this is of any help to you..


Cheers again Arduinees.

Spycatcher2k
Drew.
http://www.uk-pcb.co.uk - My UK Based PCB Fab & Assembly Company
Design work undertaken
SMD & Thru-Hole assembly

cr0sh

Please tell me, regardless of what you've done, that you didn't mount it to your Honda Civic (or whatever vehicle you have)...

/almost as bad as wearing parachute pants in the 80's...

;D
I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

spycatcher2k

;D
Nope - Never had a honda civic, it's an astra that I drive. . . .

Im doing these projects just for fun, and learning as I go.
but in saying that, if someone wanted one of my projects, then
I would gladly sell them  ;) .
We have a few 'Boy Racers' around here, so
Drew.
http://www.uk-pcb.co.uk - My UK Based PCB Fab & Assembly Company
Design work undertaken
SMD & Thru-Hole assembly

Go Up