Reputation: 11
I'm using STM32 Nucleo-L053R8
I can display a single char in 8x8 dot matrix. But my problem is how can I make a string scroll to left or right direction?
Here is the code for displaying single char in 8x8 Dot Matrix:
uint8_t myfont[36][8]={
{0x70>>2,0x88>>2,0x98>>2,0xA8>>2,0xC8>>2,0x88>>2,0x88>>2,0x70>>2}, // 0
}
dotmatrix_put(myfont[0]);
void dotmatrix_put(uint8_t *data){
for(uint8_t i=0;i<8;i++){
dotmatix_buf[i]=data[i];
}
}
Hoping for the help, Thank you in Advance!
Upvotes: 1
Views: 569
Reputation: 189
Assuming that the array you defined:
uint8_t myfont[36][8]
with [8]
is define for column.
The concept of scrolling left/right is by display another frame with shifting the column. For example:
First frame you show:
[col0, col1, col2, col3, col4, col5, col6, col7]
Second frame you show:
[col1, col2, col3, col4, col5, col6, col7, <empty>]
<empty>
is for clearing the last column after shift. If you prefer rotate, it should be col0
.
Align with your code (just example for left/right shift, you could extend for other cases), some minor change as following:
void dotmatrix_put(uint8_t *data, int8_t shift_col)
// shift_col is number of column to shift: 0 = no shift, -1 for shift left 1, 1 for shift right 1
{
uint8_t max = 7;
uint8_t min = 0;
int8_t start_col = 0;
if (shift_col > 0)
{
min = min + shift_col;
}
else
{
max = max + shift_col;
start_col = -shift_col; // get the positive or 0 number
}
for(uint8_t i=0;i<8;i++)
{
if (i >= min && i <= max)
{
dotmatix_buf[i]=data[i + start_col];
}
else
{
dotmatix_buf[i] = 0;
}
}
}
Upvotes: 0