Hi everyone.
I'm having trouble with a 7 segment LED driver based on the TLC5940.
The display has a "1" and 2x 7 segment display as I only need it to display numbers from 1-199. The display is controlled via serial connection.
I can not get channels 2-13 to light up. Channels 0 and 1 will light up, and so will 14 and 15. I´m not worried about the last two because they are lit exclusively by very simple code.
Channels 0-6 are all managed by a "for loop", and I don't understand why only the first 2 channels are addressed. The second for loop which addresses 7-14 are not lighting up at all.
I tested the TLC5940 with a basic sketch that wrote max brightness to all channels, and checked them with a LED and all the channels are functional
My problem seems to be in the code, does anyone see anything that could explain this?
Sorry about some int declarations in Icelandic.
Eining = the 3 in "123"
Tugur = the 2 in "123"
Hundrad = the 1 in "123".
#include "Tlc5940.h"
byte ledsegments [10][7] = { //10 mism tölur, 7 gildi hvert
{1,1,1,1,1,1,0},//0
{0,1,1,0,0,0,0},
{1,1,0,1,1,0,1},
{1,1,1,1,0,0,1},
{0,1,1,0,0,1,1},
{1,0,1,1,0,1,1},
{1,0,1,1,1,1,1},
{1,1,1,0,0,0,0},
{1,1,1,1,1,1,1},
{1,1,1,1,0,1,1} //9
};
int pwmOn = 4095; //max brightness
int pwmOff = 0;
void setup() {
Tlc.init();
Serial.begin(9600);
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(A2, OUTPUT);
pinMode(A3, OUTPUT);
}
int pocketNo;
int eining;
int tugur;
int hundrad;
int incoming;
int x;
int ascii;
boolean clearDisplay = true;
int y;
int row;
void loop(){
incoming = Serial.available ();
if (incoming > 0) {
ascii= Serial.read();
if (ascii == 3) {//IF enter
pocketNo = Serial.parseInt();
hundrad = pocketNo/100;
tugur = pocketNo/10;
if (tugur>=10) {
tugur = tugur-10;}
eining = pocketNo - (hundrad*100) - (tugur *10);
clearDisplay = false;
}
if (ascii == 45) { //mínus takkinn CLEAR
clearDisplay = true;
}
}
//set channels 0-6
for (x=0; x<7; x++){
Tlc.set(ledsegments[eining][x],pwmOn);
}
//set channels 7-14
for (x=7; x<14; x++){
Tlc.set(ledsegments[tugur][x-7], pwmOn);
}
if (hundrad == 0) { //Hundrað
Tlc.set(14,pwmOff);
Tlc.set(15,pwmOff);
}
if (hundrad == 1) {
Tlc.set(14,pwmOn);
Tlc.set(15,pwmOn);
}
if (clearDisplay == true)
{Tlc.clear();}
Tlc.update();
}
Thanks if you got through to here =)
Solved:
The correct for-loop should look like this
for (x=0; x<7; x++){
onOrOff = ledsegments[eining][x];
if (onOrOff == 1){
Tlc.set(x,pwmOn);
}
else {Tlc.set(x,pwmOff);}
}