Go Down

Topic: TLC5940 7 Segment Display Clock (Read 39 times) previous topic - next topic

markus2066

Hi All,

This is my first post, just getting started with the Arduino and struggling with this project somewhat. Hope someone can help and point me in the right direction, not sure I'm going about this in the right way.

I'm trying to build an Arduino 7 segment display clock using a TLC5940 to drive the LED display. I'm slowly building the code and my understanding of the components (not got very far and i'm a little stuck).


Parts:
Ardunio Uno Rev3
Common Anode 4 Dig 7 Seg Display (CL5642BH)
TLC5940 LED Driver IC


So far:

I have managed to get he display to count 0 - 9 on all digits at the same time.

Then I connected each of the 4 common anodes to digital pins to allow me to switch them on and off from within my code (I hoped this would go some way towards beginning to multiplex the display).

I hoped that I could somehow reference the parts of the code which control the TLC outputs to display numbers e.g. (the code below displays the number 2 on the display). Which which then allow me to read a value from a RTC and display that digit on the screen.....

Quote
//Display Number 2
Tlc.set(0, brightness);
Tlc.set(1, brightness);
Tlc.set(3, brightness);
Tlc.set(4, brightness);
Tlc.set(6, brightness);
delay(countdelay);

Tlc.update();
Tlc.clear();
Now I'm not sure this is possible or the best way to go about it? My end goal is to create a Nixie clock. I'm using the TLC5940 to give me enough outputs to drive 4*10 digits with high current transistors, hence the chosen method.

Any advice would be greatly appreciated. (think this is how i post code, guide ive found says 11th icon along but thats insert image)


Here is my full code (so far):

Quote
#include "Tlc5940.h"

TLC_CHANNEL_TYPE channel;

int initialdelay = 600; //delay at begining of count
int countdelay = 1000; //ms between numbers displayed
int brightness = 500; //set brightness of screen

//storage variables
boolean toggle0 = 0;

void setup(){

    Tlc.init();
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
 
cli();//stop interrupts

//set timer0 interrupt at 2kHz
  TCCR0A = 0;// set entire TCCR0A register to 0
  TCCR0B = 0;// same for TCCR0B
  TCNT0  = 0;//initialize counter value to 0
  // set compare match register for 2khz increments
  OCR0A = 124;// = (16*10^6) / (2000*64) - 1 (must be <256)
  // turn on CTC mode
  TCCR0A |= (1 << WGM01);
  // Set CS01 and CS00 bits for 64 prescaler
  TCCR0B |= (1 << CS01) | (1 << CS00);   
  // enable timer compare interrupt
  TIMSK0 |= (1 << OCIE0A);


sei();//allow interrupts

}//end setup


ISR(TIMER0_COMPA_vect){//timer0 interrupt 2kHz toggles pin 8
//generates pulse wave of frequency 2kHz/2 = 1kHz (takes two cycles for full wave- toggle high then toggle low)
  if (toggle0){
    digitalWrite(8,HIGH);
    toggle0 = 0;
  }
  else{
    digitalWrite(8,LOW);
    toggle0 = 1;
  }
}


void loop()
{

delay(initialdelay);
 
digitalWrite(4, HIGH); //Turn on ALL Digits
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
 
//Display Number 1 
Tlc.set(1, brightness);
Tlc.set(2, brightness);
delay(countdelay);

Tlc.update();
Tlc.clear();

//Display Number 2
Tlc.set(0, brightness);
Tlc.set(1, brightness);
Tlc.set(3, brightness);
Tlc.set(4, brightness);
Tlc.set(6, brightness);
delay(countdelay);

Tlc.update();
Tlc.clear();

//Display Number 3
Tlc.set(0, brightness);
Tlc.set(1, brightness);
Tlc.set(2, brightness);
Tlc.set(3, brightness);
Tlc.set(6, brightness);
delay(countdelay);

Tlc.update();
Tlc.clear();

//Display Number 4
Tlc.set(5, brightness);
Tlc.set(1, brightness);
Tlc.set(6, brightness);
Tlc.set(2, brightness);
delay(countdelay);

Tlc.update();
Tlc.clear();

//Display Number 5
Tlc.set(0, brightness);
Tlc.set(5, brightness);
Tlc.set(6, brightness);
Tlc.set(2, brightness);
Tlc.set(3, brightness);
delay(countdelay);

Tlc.update();
Tlc.clear();

digitalWrite(4, LOW); //Turn OFF First two Digits
digitalWrite(5, LOW);

//Display Number 6
Tlc.set(0, brightness);
Tlc.set(5, brightness);
Tlc.set(6, brightness);
Tlc.set(4, brightness);
Tlc.set(3, brightness);
Tlc.set(2, brightness);
delay(countdelay);

Tlc.update();
Tlc.clear();

//Display Number 7
Tlc.set(0, brightness);
Tlc.set(1, brightness);
Tlc.set(2, brightness);
delay(countdelay);

Tlc.update();
Tlc.clear();

//Display Number 8
Tlc.set(0, brightness);
Tlc.set(1, brightness);
Tlc.set(2, brightness);
Tlc.set(3, brightness);
Tlc.set(4, brightness);
Tlc.set(5, brightness);
Tlc.set(6, brightness);
delay(countdelay);

Tlc.update();
Tlc.clear();

//Display Number 9
Tlc.set(0, brightness);
Tlc.set(1, brightness);
Tlc.set(2, brightness);
Tlc.set(3, brightness);
Tlc.set(5, brightness);
Tlc.set(6, brightness);
delay(countdelay);

Tlc.update();
Tlc.clear();

//Display Number 0
Tlc.set(0, brightness);
Tlc.set(1, brightness);
Tlc.set(2, brightness);
Tlc.set(3, brightness);
Tlc.set(4, brightness);
Tlc.set(5, brightness);
delay(countdelay);

Tlc.update();
Tlc.clear();

}

void loop2()
{
Tlc.set(7, brightness);
delay(countdelay);

Tlc.update();
Tlc.clear();
}

StudentSA

Hi markus2066,

Im not sure what your question is, or where you require help.

Generally you want to use multiplexing to display the time you want. This means you need to reduce your code to a simple for loop through each digit.

You must then enable only the first digit and write that digits value, then enable only the second digit and write the digits value... etc. If you do this fast enough it will look "seemless".

Are you looking for code to do this?

Go Up