Go Down

Topic: Hi. Control 24V LED strip by Multiplexing. HELP Please!! (Read 2018 times) previous topic - next topic

Wawa

Use the first example.
The example has a 2-digit counter (which you don't need).
But ok to see it all working.

Change
number %= 100; //Reset x after 99
to
number %= 10000; //Reset x after 9999 for your 4-digit display

Then snip out the counter part, and only use
showNumber(number); // displays the value of 'number'

Get the hardware done first, then worry about the software.
Leo..

Bigtimer

Hi

i'm still waiting for my Tpic6b595 to arrive hopefully they come tomorrow .


in the meantime I found this code on the arduino forum i think will work.


Arfuino Forum page
Code: [Select]



// Boffin1's  countdown " bomb " timer with preset up down run and pause
//   connect dots  to spare TPIC output on minute units chip, on when counting down, flash when paused
#include <VirtualWire.h>
#define latchPin 19  // rck
#define clockPin 18  // sck
#define dataPin 16   // ser in

int tile [4];
//  bitmap for which leds segements ( TPIC pins ) are lit for numbers 0 - 9, first bit for dots
// this pattern will depend on how the segments are wired up
//       this pattern is for  sequence   =   dots,  e,  d,  c,  g,  b,  f,  a
const byte digitTable [10] = {
 B01110111, B00010100, B01101101, B00111101, B00011110, B00111011, B01111011, B00010101, B01111111,B00111111 }
;   

const byte blanked = B00000000;
int dotState;
int pause = HIGH;
int blank = HIGH;
int mintens = 0;
int minunits = 0;
int sectens = 0;
int secunits = 0;
int timeleft = 0;             
unsigned long previousdotMillis = 0; 
unsigned long previousMillis = 0;     
int mintendisp;
int minunitsdisp;
int sectensdisp;
int secunitsdisp; 
int plusPin = 4;
int minusPin = 5;
int runPin = 6;
int pausePin = 7;
int running;
int bombPin = 8;

//******************************************************       
void setup()
{
 Serial.begin(9600); 
 blank == HIGH;
 Serial.println("setup");
 pinMode ( latchPin, OUTPUT);
 pinMode ( clockPin, OUTPUT);
 pinMode ( dataPin, OUTPUT);
 pinMode ( plusPin, INPUT);
 digitalWrite(plusPin, HIGH); // set pullups
 pinMode ( minusPin, INPUT);
 digitalWrite(minusPin, HIGH);
 pinMode ( runPin, INPUT);
 digitalWrite (runPin, HIGH);
 pinMode ( pausePin, INPUT);
 digitalWrite(pausePin, HIGH);

 digitalWrite(latchPin, LOW);      // blanking all displays
 for ( int k=0; k<=3; k++ ){
   shiftOut(dataPin, clockPin, LSBFIRST, blank);
   delay (5);
 }
 digitalWrite(latchPin, HIGH); 
 pinMode ( bombPin, INPUT);
 digitalWrite(bombPin, LOW);
}
//********************************************************************
void loop ()


 checktime();

 if ( mintens + minunits + sectens + secunits  >= 1 ){
   timeleft = HIGH;
 }    // check again after countdown
 else
 {
   timeleft = LOW ;
   pause = HIGH;   
 }     //  flashing dots
 unsigned long currentdotMillis = millis();
 if(currentdotMillis - previousdotMillis > 500) {
   previousdotMillis = currentdotMillis;   
   if (dotState == LOW)
   {
     dotState = HIGH;
   }   
   else     {
     dotState = LOW;
   } 
   showtime ();
 }
 if ( pause == LOW ) {
   dotState = HIGH ;
 }

 

 checkbutton ();   


}//  end of loop


void checktime () {
 if ( mintens + minunits + sectens + secunits  >= 1 )  //  if time still left on countdown
 {
   timeleft = HIGH;
 }
 else {
   timeleft = LOW ;
   pause = HIGH;
 }

 if (timeleft == HIGH ) {
   if ( pause == LOW ) {  //  which means its counting down   i.e. not paused in countdown         
     static unsigned long previousMillis;
     if(millis() > previousMillis)
     {
       previousMillis = millis() + 1000;
       secunits -- ;             // countdown 1 sec
       if ( secunits  < 0 ){
         secunits = 9; 
         sectens -- ;
       }
       if ( sectens   < 0 ){
         sectens = 5; 
         minunits -- ;
       }
       if ( minunits  < 0 ){
         minunits = 9; 
         mintens -- ;
       }
       // mintens cant get to -1 or it would have to have been 0000 and paused
       Serial.print(mintens); 
       Serial.print(minunits); 
       Serial.print(" : ");
       Serial.print(sectens); 
       Serial.println(secunits);
       showtime ();

       if ( mintens + minunits + sectens + secunits  >= 1 ){
         timeleft = HIGH;
       }
       else {
         digitalWrite( bombPin, HIGH ) ;
         timeleft = LOW ;
         pause = HIGH ;
                // milliseconds bombPin goes high
         delay ( 2000 );
       }
       digitalWrite( bombPin, LOW );

     }
     dotState = HIGH;
   } // keeps dots on while countdown
   else
     if ( blank == LOW ) {
     flashdots ();
   }

 }
} // END OF CHECKTIME

void checkbutton ()
{   
 int plus = digitalRead( plusPin );
 if ( plus == LOW ) {     
   secunits ++; 
 } 

 if ( secunits > 9 ){       
   secunits = 0 ;       
   sectens ++;   
 }
 if ( sectens >5 ) {     
   sectens = 0;     
   minunits ++;   
 }
 if ( minunits > 9 ){     
   minunits=0;       
   mintens ++;   
 }
 if ( mintens >5 ){       
   mintens = 0 ;   
 }   

 int minus = digitalRead( minusPin );
 if ( minus == LOW ) { 
   secunits --;
 }

 if ( secunits  < 0 ){       
   secunits = 9;       
   sectens -- ;   
 }
 if ( sectens   < 0 ){       
   sectens = 5;       
   minunits -- ;   
 }
 if ( minunits  < 0 ){       
   minunits = 9;       
   mintens -- ;   
 } 
 if ( mintens < 0 ){       
   mintens =5 ;     
 }

 //  CHANGE THIS DELAY TO SET COUNTSPEED WHEN + or - BUTTON HELD IN
 if ( plus || minus == LOW ){ 
   delay ( 100 ) ;     
   showtime ();     
 } 


 // when run button pressed release pause
 int runbutton = digitalRead( runPin );
 if ( runbutton == LOW ) {
   pause = LOW ;
 }


 // when pause button pressed  set pause
 int pausebutton  = digitalRead( pausePin ); 
 if ( pausebutton == LOW ) {
   pause = HIGH ;
 }



}  // end of checkbutton function

void flashdots () {
 unsigned long currentdotMillis = millis();
 if(currentdotMillis - previousdotMillis > 500) {
   previousdotMillis = currentdotMillis;   
   if (dotState == LOW)
   {
     dotState = HIGH;
   }
   else  {
     dotState = LOW;
   }     
   showtime (); 
 }
 if ( pause == LOW ) {
   dotState = HIGH ;
 } 
} //  end of flashdots routins

void showtime ()   //  DISPLAY ROUTINE
{   
 int mintendisp = (mintens) ? digitTable [ mintens ] : 0;  //  zero blanking tens minutes
 int minunitsdisp = digitTable [ minunits ];
 int sectensdisp = digitTable [ sectens ];
 int secunitsdisp = digitTable [ secunits ];
 if ( dotState == HIGH ){

   minunitsdisp = minunitsdisp|10000000 ;
 }      //   adds msb to minunit to light dots when dotState high

 digitalWrite(latchPin, LOW);

 shiftOut(dataPin, clockPin, LSBFIRST, mintendisp);
 shiftOut(dataPin, clockPin, LSBFIRST, minunitsdisp);
 shiftOut(dataPin, clockPin, LSBFIRST, sectensdisp);
 shiftOut(dataPin, clockPin, LSBFIRST, secunitsdisp);

 digitalWrite(latchPin, HIGH);
}

PaulRB

Maybe your can use some lines of code from that sketch, but most of it is pretty lousy.

Bigtimer

So i have just run my circuit for the fist time now I have the Chips, I ran it with that code with just one display connected, and the display started to flashing on and off which i supposes means that something is working at least.

how-ever the bad  new is one of my 47uF capacitors went BOOM!!! lol

any ideas why this could be?

it had 24v going through it?


Grumpy_Mike

The capacitor will go boom if the rating voltage is less than the 24V you are putting across it.

It will also go boom if you connected it the wrong way round.

There is not much of it left to see which one it was.


Bigtimer

do you guys know of any simple count down code that i could use just to test this thing. i have no idea how to code it

Wawa

So the Sparkfun countUP code I linked to doesn't work?

int number = 0;
change that to
int number = 9999;
and
number++;
to
number--;
for a 4digit count down display.
Leo.

Bigtimer

ok ive done that. using the code of sparkfun that you said.

but it is not printing numbers. it is just turning each LED segment on one after another.

PaulRB

Here is the test sketch I am using at the moment while I construct my 7-seg display:
Code: [Select]

#include <SPI.h>

#define LATCH D8

SPISettings tpic6c595(10000000UL, MSBFIRST, SPI_MODE0);

byte digitPattern[10] = {
  0b0111111,
  0b0000110,
  0b1011011,
  0b1001111,
  0b1100110,
  0b1101101,
  0b1111101,
  0b0000111,
  0b1111111,
  0b1101111
};

void setup() {
  pinMode(LATCH, OUTPUT);
  Serial.begin(115200);
  SPI.begin();
  SPI.beginTransaction(tpic6c595);
}

void loop() {
  for (int i = 0; i <= 9; i++) {
    SPI.transfer(digitPattern[i]);
    digitalWrite(LATCH, HIGH);
    digitalWrite(LATCH, LOW);
    delay(500);
  }

}

Grumpy_Mike

16v its says on it
So now you know why it went boom when you connected it to 24V

Bigtimer

Hi guy's hope you are all doing well. Yes I think figured out 'Boom Boom' haha

I have final got to point where I think I am beginning to make some progress. Problem is my deadline for this project is tomorrow, so as crap as the code is at the moment, it works to sum degree. I will come back to it very soon to make it the best it can be But for now it will do.

I final managed to make the clock display numbers. Turns out it was the Boolen numbers are back to front '0' would turn the display on and '1' it off so once I swooped them all around I had a clock that would count up.

Now all I had to do was make it count down. I'm sure there is a supper easy way to do this but I just couldn't figure it out.

Something like for(int i=0; ,i>=0;  i--)

But when I tried that nothing happened

So what I have done is reversed the order in which the boolen numbers are in to to count up backwards 'LOL' {9, 8 ,7, 6, 5, 4, 3 ,2, 1, 0,} I know its crude but it works

Code: [Select]

#define LATCH 6
#define DATA 7
#define CLK 5

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=



//This is the hex value of each number stored in an array by index num

byte digitOne[10]= {B00011001, B00000001, B01111001, B00000011, B00010011, B10011001, B01010001, B01000101, B11111001, B00100001};

byte digitTwo[10]= {B00011001, B00000001, B01111001, B00000011, B00010011, B10011001, B01010001, B01000101, B11111001, B00100001};

byte digitThree[6]= { B00010011, B10011001, B01010001, B01000101, B11111001, B00100001}; // online 6 number for the minets

byte digitFour[10]= {B00011001, B00000001, B01111001, B00000011, B00010011, B10011001, B01010001, B01000101, B11111001, B00100001};


int i;

void setup(){
 
  pinMode(LATCH, OUTPUT);
  pinMode(CLK, OUTPUT);
  pinMode(DATA, OUTPUT);

   
   
}

void loop(){
//  Count down

    for(int l=0; l<10; l++){
  for(int k=0; k<10; k++){
    for(int j=0; j<6; j++){
  for(int i=0; i<10; i++){
   
     
       
      digitalWrite(LATCH, LOW);
      shiftOut(DATA, CLK, LSBFIRST, ~digitFour[i]); // digitTwo
      shiftOut(DATA, CLK, LSBFIRST, ~digitThree[j]); // digitOne
      shiftOut(DATA, CLK, LSBFIRST, ~digitTwo[k]); // digitTwo
      shiftOut(DATA, CLK, LSBFIRST, ~digitOne[l]); // digitOne
      digitalWrite(LATCH, HIGH);
      delay(5);

      if(i+j+k+l);=0{ // this code dose not work im not sure why
       digitalWrite(LATCH, LOW);
      shiftOut(DATA, CLK, LSBFIRST, B11111111,); // digitTwo
       digitalWrite(LATCH, HIGH)
       delay(1000000);
       
      }
    }
  }
    }
  }
}

//That's all for shift registers!


Now all I need is a little bit of to stop the clock when it gets to '0' so It doesn't go 99:99 agiain

Also a little bit of code to start the clock of in the first place would be nice. Like a push to start button.

Hope you Guys can help me with this final task, would be much appreciated

Grumpy_Mike

Code: [Select]
if(i+j+k+l);=0{ // this code dose not work im not sure why
Because the if statement is not correct. Do you mean
Code: [Select]
if(i+j+k+l=0){

Quote
Something like for(int i=0; ,i>=0;  i--)
No, just read what it says.

Set the variable i to be zero
While the variable i is greater than zero do what is in the block following the "if" :- now as i is set to zero it can never be greater than zero so the statements after the "if" can never be run.

Go Up