(Solved)Again problem with matrix, this time 8x32

Status
Not open for further replies.
ohya, looking back at post 9, you wanted to do a counter not a clock, but you want the counter to scroll correct?
 
That counter was just for testing purposes, but we can of course test that too with this code structure, scrolling was the main issue .
 
okay! well im working on the font map & a scroll function,

is there anything we want to do specific in the main?
 
Well, for now any scrolling text would be enough, nothing fancy is needed at main, at least I can't think of anything.
 
k try this! plus another fontmap!


int dataPin = 2; // ic: 14, ser_in Define which pins will be used for the Shift Register control
int latchPin = 3; // ic:12 silkscreen numbers!
int clockPin = 4;


unsigned char displayPointer=0; // for interrupt use...
unsigned char buffer1[32]; // buffer for screen
unsigned char backbuffer[32]; // Spare screen for drawing on
unsigned char power[8]={128,64,32,16,8,4,2,1};

ISR(TIMER1_COMPA_vect) // timer compare interrupt service routine
{
if(TIFR2) // Make sure its the timer interrupt.
{
setcolumn(displayPointer);
setdata(buffer1[displayPointer]);
digitalWrite(latchPin ,HIGH);digitalWrite(latchPin , LOW ); // STORECLOCK
if(++displayPointer==32) { displayPointer = 0; } // 32 LED row sections in total
}
TIFR2 = 0; // Clear timer 2 interrupt flag


}

void setcolumn(unsigned char col){
signed char pos;
for (pos = 32;pos>-1;pos--){
if (col == pos){digitalWrite(dataPin ,HIGH);}else {digitalWrite(dataPin ,LOW);} // PIN1 DATA pin
digitalWrite(clockPin ,HIGH);digitalWrite(clockPin ,LOW);
}}

void setdata(unsigned char dat){
unsigned char pos;
for (pos = 0;pos<8;pos++){
if (dat & 128){dat-=128;digitalWrite(dataPin ,HIGH);}else { digitalWrite(dataPin ,LOW);} // PIN1 DATA pin
dat = dat * 2;
digitalWrite(clockPin ,HIGH);digitalWrite(clockPin ,LOW);
}}
void clr() //clear
{
int addr;
for(addr=0;addr<32;addr++) // Empty display buffer
backbuffer[addr]= 0;
}

void Blit() //transfers data between display buffer to screen buffer
{
int addr=0;
noInterrupts(); // disable all interrupts during setup
for(addr=0;addr < 32;addr ++)
{
buffer1[addr] = backbuffer[addr]; // put all data from display buffer
} // to screen buffer
interrupts(); // enable all interrupts
}

void pixel(signed char x,signed char y,int cond)
{
unsigned char pix,msk;
if(x<0 || y<0) return; // outside drawing limits negative
if(x>31 || y>7) return; // outside drawing limits positive
pix = power[y];
msk = backbuffer[x]; // get exsisting data


if(cond == 2)
pix ^= msk; // XOR data to screen
if (cond == 1)
{
pix = ~pix;
pix &= msk; // AND data to screen
}
if(cond == 0)
pix |= msk; // OR data to screen
backbuffer[x] = pix; // apply changes
}

void charput(unsigned char ch, signed char x,signed char y)
{
signed char x1, y1;
unsigned char disp;
unsigned char disp2;
for( x1=0;x1<8;x1++) // eight rows
{
disp = font[x1+(ch * 8)];
for (y1 = 0; y1<8; y1++) // eight pixels
{
disp2 = disp & power[y1];
if(disp2 > 0)
{
pixel(x+x1,y+y1,0); // OR the pixel to the display buffer
}
}

}
}

void strput(const char* ch, signed char x,signed char y)
{
int addr;
while (*ch )
{
charput(*ch++,x,y); // write a string to the display buffer
x+=7;
}
}



void setup() //setup runs once
{
signed char cntr;
noInterrupts(); // disable all interrupts during setup
DDRD = DDRD | B11111100; //port registers used to set pin directions
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
OCR1A = 5; // compare match register 16MHz/256/2Hz -----------------------------------> delay time (lcd flicker/brightness)
TCCR1B |= (1 << WGM12); // CTC mode, free-running, clear on match
TCCR1B |= (1 << CS12); // 256 prescaler
TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt
interrupts(); // enable all interrupts

} // End main

void loop() //just sitting here
{
signed char scrollctr;
unsigned char numCTR;

clr();
strput("WOOF",0,0);
blit();
Delay(500);

for (scrollctr=-8;scrollctr<9;scrollctr++)
{
clr();
strput("WOOF",0,scrollctr);
blit();
Delay(200);
}

for (scrollctr=-32;scrollctr<33;scrollctr++)
{
clr();
strput("WOOF",scrollctr,0);
blit();
Delay(200);
}

for (numCTR=0;numCTR<10;numCTR++){
for (scrollctr=-8;scrollctr<9;scrollctr++)
{
clr();
charput(numCTR,24,scrollctr);
blit();
Delay(200);
}
}



}
 

Attachments

  • FontMap.h
    8.5 KB · Views: 313
just delete the old ones..... we have history here in forum, really you can just open it and cut and paste, then throw it away.
 
Hehe, about code, there were couple small typos, after fixing them, screen displays ''WOOF'', which disappears, and then slowly scroll from down to up, all the way until it can't be seen anymore.
I have feeling this was as intended?
 
also we should be mostly done with the fontmap, I populated all the numbers and the important letters, so that should be it..... haha... if you need more letters , i will let you populate them!

also idk if i mentioned that blocks 0-9 are used for numbers, and Ascii symbols start at 32, so blocks 10-31 are free for you if you want to do custom characters.....

here is software i designed on visual studio 2012, custom to your display, you can use if you want, I put exe for those who dont care in publish.zip, but added source code too for those who do, in display_font.zip!
 

Attachments

  • FontMap.zip
    473.9 KB · Views: 292
Hehe, about code, there were couple small typos, after fixing them, screen displays ''WOOF'', which disappears, and then slowly scroll from down to up, all the way until it can't be seen anymore.
I have feeling this was as intended?

yup!
 
and after that, rightmost matrix displays 0-9 counter, flowing down to up!
YUP! ......post vid pls! also post fixed code pls!

so in the main, you can see the 3 examples of how i did it, are you good from there? anything else we want to do/add?
 
sorry for delay, had paracord kechain to be made (handy while thinking stuff like codes , once it comes automatic routine)
Here's full code, I can also post video but I have feeling that takes long time to upload, then again, I'm in no rush.
Gotta take some time to understand that code hehe.
perhaps next thing would be to implement RTC or similar data to show, so matrix would have some purpose
I edited delay() values for it to scroll faster, helped bit.
C:
#include "FontMap.h"

int dataPin = 2; // ic: 14, ser_in Define which pins will be used for the Shift Register control
int latchPin = 3; // ic:12 silkscreen numbers!
int clockPin = 4;


unsigned char displayPointer=0; // for interrupt use...
unsigned char buffer1[32]; // buffer for screen
unsigned char backbuffer[32]; // Spare screen for drawing on
unsigned char power[8]={128,64,32,16,8,4,2,1};

ISR(TIMER1_COMPA_vect) // timer compare interrupt service routine
{
if(TIFR2) // Make sure its the timer interrupt.
{
setcolumn(displayPointer);
setdata(buffer1[displayPointer]);
digitalWrite(latchPin ,HIGH);digitalWrite(latchPin , LOW ); // STORECLOCK
if(++displayPointer==32) { displayPointer = 0; } // 32 LED row sections in total
}
TIFR2 = 0; // Clear timer 2 interrupt flag


}

void setcolumn(unsigned char col){
signed char pos;
for (pos = 32;pos>-1;pos--){
if (col == pos){digitalWrite(dataPin ,HIGH);}else {digitalWrite(dataPin ,LOW);} // PIN1 DATA pin
digitalWrite(clockPin ,HIGH);digitalWrite(clockPin ,LOW);
}}

void setdata(unsigned char dat){
unsigned char pos;
for (pos = 0;pos<8;pos++){
if (dat & 128){dat-=128;digitalWrite(dataPin ,HIGH);}else { digitalWrite(dataPin ,LOW);} // PIN1 DATA pin
dat = dat * 2;
digitalWrite(clockPin ,HIGH);digitalWrite(clockPin ,LOW);
}}
void clr() //clear
{
int addr;
for(addr=0;addr<32;addr++) // Empty display buffer
backbuffer[addr]= 0;
}

void Blit() //transfers data between display buffer to screen buffer
{
int addr=0;
noInterrupts(); // disable all interrupts during setup
for(addr=0;addr < 32;addr ++)
{
buffer1[addr] = backbuffer[addr]; // put all data from display buffer
} // to screen buffer
interrupts(); // enable all interrupts
}

void pixel(signed char x,signed char y,int cond)
{
unsigned char pix,msk;
if(x<0 || y<0) return; // outside drawing limits negative
if(x>31 || y>7) return; // outside drawing limits positive
pix = power[y];
msk = backbuffer[x]; // get exsisting data


if(cond == 2)
pix ^= msk; // XOR data to screen
if (cond == 1)
{
pix = ~pix;
pix &= msk; // AND data to screen
}
if(cond == 0)
pix |= msk; // OR data to screen
backbuffer[x] = pix; // apply changes
}

void charput(unsigned char ch, signed char x,signed char y)
{
signed char x1, y1;
unsigned char disp;
unsigned char disp2;
for( x1=0;x1<8;x1++) // eight rows
{
disp = font[x1+(ch * 8)];
for (y1 = 0; y1<8; y1++) // eight pixels
{
disp2 = disp & power[y1];
if(disp2 > 0)
{
pixel(x+x1,y+y1,0); // OR the pixel to the display buffer
}
}

}
}

void strput(const char* ch, signed char x,signed char y)
{
int addr;
while (*ch )
{
charput(*ch++,x,y); // write a string to the display buffer
x+=7;
}
}



void setup() //setup runs once
{
signed char cntr;
noInterrupts(); // disable all interrupts during setup
DDRD = DDRD | B11111100; //port registers used to set pin directions
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
OCR1A = 5; // compare match register 16MHz/256/2Hz -----------------------------------> delay time (lcd flicker/brightness)
TCCR1B |= (1 << WGM12); // CTC mode, free-running, clear on match
TCCR1B |= (1 << CS12); // 256 prescaler
TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt
interrupts(); // enable all interrupts

} // End main

void loop() //just sitting here
{
signed char scrollctr;
unsigned char numCTR;

clr();
strput("WOOF",0,0);
Blit();
delay(5);

for (scrollctr=-8;scrollctr<9;scrollctr++)
{
clr();
strput("WOOF",0,scrollctr);
Blit();
delay(5);
}

for (scrollctr=-32;scrollctr<33;scrollctr++)
{
clr();
strput("WOOF",scrollctr,0);
Blit();
delay(5);
}

for (numCTR=0;numCTR<10;numCTR++){
for (scrollctr=-8;scrollctr<9;scrollctr++)
{
clr();
charput(numCTR,24,scrollctr);
Blit();
delay(5);
}
}
}
 
Last edited:
yes, whatever looks best, also feel free to adjust this value:
OCR1A = 5; // compare match register 16MHz/256/2Hz -----------------------------------> delay time (lcd flicker/brightness)

too fast will over dim the leds, too slow will cause flickering
 
the main functions to understand are: pixel, charput, strput

pixel(x,y,c) where x and y are the position on map, and c is how we operate it in, not really sure what the 1 & 2 values will do! but this function will prolly be used least.
charput(s,x,y) again x,y is the start point and s is the character loaded from fontmap.....
strput("",x,y) same here, x,y is startpoint, and "" is the string that will be written in.

from there we are able to scroll using a for loop that changes the y value 1 by 1.

to get a RTC going it may be easier to setup another interrupt.
 
Should the interrupt be external (with square wave from RTC chip, 1hz) or another timer interrupt? I use those i2c RTC's
 
if it works, I'v never used, so dont know how,do know a bit about i2c, what is part number?
isnt external used with watch battery so it doesnt forget the time?
might be a good idea!
 
Last edited:
pixel(x,y,c)
0 = OR the pixel to the screen ie... add the new data to the old
1 = AND the pixel to the screen ie.. Only if the pixel was already lit it will stay lit ( in other words delete it )
2 is the one to use... XOR the pixels... This will light the pixel if it was off and extinguish if it was on..
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…