Moderators: adafruit_support_bill, adafruit
#include "RGBmatrixPanel.h"
#define A A0
#define B A1
#define C A2
#define CLK 8
#define LAT A3
#define OE 9
#define WIDTH 32
int count = 0;
byte currentByte = 0;
byte lastByte = 0;
uint16_t color;
RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, true);
void setup()
{
Serial.begin(115200);
matrix.begin();
}
void loop() {
int index;
while (Serial.available()) {
lastByte = currentByte;
currentByte = Serial.read();
// Look for the frame marker 0xF000
if ((lastByte == 0xF0) && (currentByte == 0x00)) {
count = 0;
matrix.swapBuffers(false);
} else {
if ((count % 2) == 1) {
color = (lastByte << 8) | currentByte;
index = (count-1)/2;
matrix.drawPixel(index % WIDTH, index / WIDTH, color);
}
count++;
}
}
}RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, true);RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, true);#include <Adafruit_GFX.h> // Core graphics library
#include <RGBmatrixPanel.h> // Hardware-specific library
#include <avr/pgmspace.h>
#define A A3
#define B A2
#define C A1
#define D A0
#define CLK 8 // MUST be on PORTB!
#define LAT 9
#define OE 10
#define WIDTH 32
#define HEIGHT 32
int count = 0;
byte currentByte = 0;
byte lastByte = 0;
uint16_t color;
RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false);
void setup()
{
Serial.begin(115200);
matrix.begin();
}
void loop() {
int index;
while (Serial.available()) {
lastByte = currentByte;
currentByte = Serial.read();
// Look for the frame marker 0xF0
if ((lastByte == 0xF0) && (currentByte == 0x00))
{
count = 0;
matrix.swapBuffers(false);
}
else
{
if ((count % 2) == 1)
{
color = (lastByte << 8) | currentByte;
index = (count-1)/2;
matrix.drawPixel(index % WIDTH, index / HEIGHT, color);
}
count++;
}
}
} // Look for the frame marker 0xF0
if ((lastByte == 0xF0) && (currentByte == 0x00))
I could be wrong, but it looks like the frame marker should be a single byte, value of 1.
// Look for the frame marker 0x1
if ((lastByte == 0x1) && (currentByte == 0x0))
The Arduino doesn't have enough RAM memory to stream and probably to show BMP pics either.
ISR(USART_RX_vect)
{
volatile unsigned char RecievedChar;
RecievedChar=UDR0;
if (RecievedChar == CMD_NEW_DATA) {UDR0=RecievedChar; pos=0; ptr=display_buffer; return;}
if (pos == 3072) {UDR0=RecievedChar; return;} else {*ptr=RecievedChar; ptr++; pos++;}
}
#include <gamma.h>
#include <RGBmatrixPanel.h>
#include <Adafruit_GFX.h> // Core graphics library
#include <avr/pgmspace.h>
PROGMEM prog_uint16_t exp_table[] =
{
0,15,15,16,16,16,17,17,17,18,18,19,19,20,20,20,21,21,22,22,23,23,24,24,25,25,26,27,27,28,28,29,30,30,31,32,32,33,34,35,35,36,37,38,39,39,40,41,42,43,44,45,46,
47,48,49,50,51,53,54,55,56,57,59,60,61,63,64,65,67,68,70,72,73,75,76,78,80,82,83,85,87,89,91,93,95,97,99,102,104,106,109,111,114,116,119,121,124,127,130,132,
135,138,141,145,148,151,154,158,161,165,169,172,176,180,184,188,192,197,201,206,210,215,220,225,230,235,240,245,251,256,262,268,274,280,286,292,299,305,312,319,
326,334,341,349,356,364,372,381,389,398,407,416,425,434,444,454,464,474,485,496,507,518,529,541,553,566,578,591,604,618,631,645,660,674,689,705,720,736,753,770,
787,804,822,840,859,878,898,918,938,959,980,1002,1024,1047,1070,1094,1119,1143,1169,1195,1221,1249,1276,1305,1334,1364,1394,1425,1457,1489,1522,1556,1591,1626,
1662,1699,1737,1775,1815,1855,1897,1939,1982,2026,2071,2117,2164,2212,2262,2312,2363,2416,2470,2524,2581,2638,2697,2757,2818,2881,2945,3010,3077,3146,3216,3287,
3360,3435,3511,3590,3669,3751,3834,3920,4007,4095
};
#define A A3
#define B A2
#define C A1
#define D A0
#define CLK 8 // MUST be on PORTB!
#define LAT 9
#define OE 10
#define WIDTH 32
#define HEIGHT 32
#define Gray_Scale_Depth 4095
#define CMD_NEW_DATA 1
unsigned char display_buffer[3072];
volatile byte new_row = 0;
volatile byte need_lat = 0;
static unsigned char *ptr;
static unsigned int pos = 0;
byte row = 0;
int count = 0;
byte currentByte = 0;
byte lastByte = 0;
uint16_t color;
RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false);
void setup()
{
Serial.begin(1000000);
matrix.begin();
// //Timer 1 (16bit)
// TCCR1A = (1<<WGM11) | (0<<WGM10); // Fast PWM with ICR1 as top
// TCCR1B = (1<<WGM13) | (1<<WGM12); // Fast PWM with ICR1 as top
// TCCR1B |= (1<<CS12) | (1<<CS11) | (1<<CS10); // external clock (T1) on rising egde
// TIMSK1 |= (1<<TOIE1); // enable overflow interupt
// ICR1 = Gray_Scale_Depth; // Grey scale depth for TLC-PW
// //Timer 0 (8bit)
// TCCR0A = (1<<WGM01) | (0<<WGM00); // CTC
TCCR0A |= (0<<COM0A1) | (1<<COM0A0); // Toggle on Compare Match
// TCCR0B = (0<<CS02) | (0<<CS01) | (1<<CS00); // No Prescaler
// OCR0A = 0; // f(OCR) = F_CPU/2/Prescaler
//UART Initialisation
UCSR0A |= (1<<U2X0); // Double up UART
UCSR0B |= (1<<RXEN0) | (1<<TXEN0) | (1<<RXCIE0); // UART RX, TX und RX Interrupt enable
UCSR0C |= (1<<UCSZ01) | (1<<UCSZ00) ; // Asynchrous 8N1
UBRR0H = 0;
UBRR0L = 1; //Baud Rate 1 MBit --> 0% Error at 16MHz :-)
//Enable global interrupts
sei();
//Configure SPI
SPCR = (1<<SPE)|(1<<MSTR);
SPSR = B00000000;
ptr=display_buffer;
}
void loop()
{
if (new_row)
{
shift_out_data(row);
need_lat = 1;
new_row = 0;
}
if (need_lat)
{
matrix.updateDisplay();
}
row++;
if (row == 32) {row = 0; matrix.swapBuffers(false);}
new_row = 1;
}
ISR(USART_RX_vect)
{
volatile unsigned char RecievedChar;
RecievedChar=UDR0;
if (RecievedChar == CMD_NEW_DATA) {UDR0=RecievedChar; pos=0; ptr=display_buffer; return;}
if (pos == 3072) {UDR0=RecievedChar; return;} else {*ptr=RecievedChar; ptr++; pos++;}
}
void spi_transfer(byte data)
{
SPDR = data; // Start the transmission
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
{
};
}
void shift_out_data(byte row)
{
unsigned int index_offset = (row) * 96;
//Shift Out Blue Data
for(byte i = 0; i<32; i++)
{
unsigned int index = index_offset + 6*(i) + 2;
unsigned int t1 = pgm_read_word_near(exp_table + display_buffer[index + 3]);
unsigned int t2 = pgm_read_word_near(exp_table + display_buffer[index]);
byte d1 = (highByte(t2) << 4) | (lowByte(t2) >> 4);
spi_transfer(d1);
byte d2 = (lowByte(t2) << 4) | (highByte(t1));
spi_transfer(d2);
byte d3 = (lowByte(t1));
spi_transfer(d3);
}
//Shift Out Green Data
for(byte i = 0; i<32; i++)
{
unsigned int index = index_offset + 6*(i) + 1;
unsigned int t1 = pgm_read_word_near(exp_table + display_buffer[index + 3]);
unsigned int t2 = pgm_read_word_near(exp_table + display_buffer[index]);
byte d1 = (highByte(t2) << 4) | (lowByte(t2) >> 4);
spi_transfer(d1);
byte d2 = (lowByte(t2) << 4) | (highByte(t1));
spi_transfer(d2);
byte d3 = (lowByte(t1));
spi_transfer(d3);
}
//Shift Out Red Data
for(byte i = 0; i<32; i++)
{
unsigned int index = index_offset + 6*(i);
unsigned int t1 = pgm_read_word_near(exp_table + display_buffer[index + 3]);
unsigned int t2 = pgm_read_word_near(exp_table + display_buffer[index]);
byte d1 = (highByte(t2) << 4) | (lowByte(t2) >> 4);
spi_transfer(d1);
byte d2 = (lowByte(t2) << 4) | (highByte(t1));
spi_transfer(d2);
byte d3 = (lowByte(t1));
spi_transfer(d3);
}
}
Return to Glowy things (LCD, LED, TFT, EL) purchased at Adafruit
Users browsing this forum: No registered users and 4 guests