Hello,
I'm trying to find a simple way to scroll data in multiple 8x8 LED matrix modules. So far I can scroll anything but it synchronized with the other modules.
I want to control the flow of the data as if I want; for example, to scroll a text so it should start from the first module moving to the last.
As in this YouTube video:
https://www.youtube.com/watch?v=e_pY-uGkDFA&t=17s
I downloaded the code provided in the link, but it's a set a libraries and the main class is really complicated and has a lot of functions. Of course, it would be very useful to understand all those libraries :)
Anyway, here's the code I developed to do the basic things and the most important is to scroll a text to any direction.
In `led_scroll()` I set the loop for 32 to see if I can provide a space between the start and the end of the scroll process.
void SPI_Init(void); void SPI_TX_s16(uint16_t data); void SPI_TX_m16(uint16_t data, uint8_t cnt); void MAX7219_init(void); void draw(void); void led_scroll(void); void clr(void); uint8_t Alphabet[208]= { 0x42, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x7e, 0x0, //A 0x3e, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x3e, 0x0, //B 0x3c, 0x42, 0x2, 0x2, 0x2, 0x42, 0x3c, 0x0 ,//C 0x3e, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3e, 0x0, //D 0x7e, 0x2, 0x2, 0x7e, 0x2, 0x2, 0x7e, 0x0 ,//E 0x2, 0x2, 0x2, 0x3e, 0x2, 0x2, 0x7e, 0x0, //F 0x3c, 0x42, 0x62, 0x2, 0x2, 0x42, 0x3c, 0x0, //G 0x42, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x42, 0x0, //H 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x0, //I 0x18, 0x24, 0x20, 0x20, 0x20, 0x20, 0x70, 0x0, //J 0x22, 0x12, 0xa, 0x6, 0xa, 0x12, 0x22, 0x0, //K 0x7e, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x0, //L 0x41, 0x41, 0x41, 0x49, 0x55, 0x63, 0x41, 0x0, //M 0x41, 0x61, 0x51, 0x49, 0x45, 0x43, 0x41, 0x0, //N 0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x0, //O 0x2, 0x2, 0x2, 0x3e, 0x42, 0x42, 0x3e, 0x0, //P 0xbc, 0x62, 0x52, 0x42, 0x42, 0x42, 0x3c, 0x0,//Q 0x62, 0x12, 0xa, 0x3e, 0x42, 0x42, 0x3c, 0x0, //R 0x1c, 0x22, 0x4, 0x8, 0x10, 0x22, 0x1c, 0x0, //S 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x3e, 0x0, //T 0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x0, //U 0x8, 0x14, 0x22, 0x41, 0x41, 0x41, 0x41, 0x0, //V 0x63, 0x55, 0x49, 0x41, 0x41, 0x41, 0x41, 0x0, //W 0x41, 0x22, 0x14, 0x8, 0x14, 0x22, 0x41, 0x0, //X 0x8, 0x8, 0x8, 0x8, 0x14, 0x22, 0x41, 0x0, //Y 0x3e, 0x2, 0x4, 0x8, 0x10, 0x20, 0x3e, 0x0 //Z }; uint8_t s=0,i,l,k,row,col,data_buffer[64]; uint16_t data; void setup() { SPI_Init(); MAX7219_init(); } void loop() { clr(); led_scroll(); _delay_ms(200); } ///////////////////////////////////////////////// // SPI functions // //////////////////////////////////////////////// void SPI_Init(void) { DDRB |= (1<<DDB3)|(1<<DDB5)|(1<<DDB2); // DDB3 MOSI, DDB5 SCrow, DDB2 SS SPCR = (1<<SPE)|(1<<MSTR); // SPI enable, Master Mode } void SPI_TX_s16(uint16_t data) { PORTB &= ~(1<<PB2); SPDR = data>>8; while(!(SPSR & (1<<SPIF))); SPDR = data; while(!(SPSR & (1<<SPIF))); PORTB |= (1<<PB2); } // this function to send data to a specific LED module void SPI_TX_m16(uint16_t data, uint8_t cnt) { PORTB &= ~(1<<PB2); uint8_t i; for (i=0;i<4;i++) { if (i==cnt) { SPDR = data>>8; while(!(SPSR & (1<<SPIF))); SPDR = data; while(!(SPSR & (1<<SPIF))); } else { SPDR = 0x00>>8; while(!(SPSR & (1<<SPIF))); SPDR = data; while(!(SPSR & (1<<SPIF))); } } PORTB &= ~(1<<PB2); PORTB |= (1<<PB2); } ///////////////////////////////////////////////// // MAX7219 functions // //////////////////////////////////////////////// void MAX7219_init(void) { SPI_TX_s16(0x0A00); // intensity SPI_TX_s16(0x0900); // decode mode SPI_TX_s16(0x0B07); // scan limit SPI_TX_s16(0x0F00); SPI_TX_m16(0x0C01,4); // shutdown on } void led_scroll(void) { col=0; for (i=0;i<32;i++) { SPI_TX_s16(data = (1<<8) | (0x0f<<col++)); _delay_ms(300); } } void clr(void) { for (i=1;i<9;i++) SPI_TX_m16(data = i<<8 | (0x00),4); }