Skip to content

Instantly share code, notes, and snippets.

@sovcik
Last active August 10, 2016 15:46
Show Gist options
  • Select an option

  • Save sovcik/7a93756c392f4f29cebe7538cc03de5d to your computer and use it in GitHub Desktop.

Select an option

Save sovcik/7a93756c392f4f29cebe7538cc03de5d to your computer and use it in GitHub Desktop.
Simple Arduino sketch showing how to control RGB LED panel 32x16, scan 1/8.
/*
* Simple sketch controlling RGB LED panel 32x16 scan rate 1/8
* Panel needs to be continuosly redrawn in order to power LEDs.
*
* Pins:
* R1,R2 - red led for upper & lower half
* G1,G2 - green led for upper & lower half
* B1,B2 - blue led for upper & lower half
*
* A,B,C - row selector = 2^3 = 8 rows (upper & lower halves x 8 = 16 rows)
*
* CLOCK - clock (flash to notify panel that bits has been sent)
* LP - latch/strobe (notify panel that row has been sent)
* OE
*
* Simple procedure:
*
* 1) Clock in data for entire row (use R1,G1,B1,R2,G2,B2 for data and CLK for clock)
* 2) OE high
* 3) Select line address (A,B,C,D)
* 4) LAT high
* 5) LAT low
* 6) OE low
*
* Repeat 1-6 for each line
*/
// buffer containing bits for RED LEDs
uint32_t buffRed[16];
// row selector 0-7
int AP = 10; // A Pin
int BP = 9; // B Pin
int CP = 8; // C Pin
// pins for RED LEDs
int R1P = 12; // R1 Pin
int R2P = 11; // R2 Pin
// pins for BLUE LEDs
int B1P = A1; // B1 Pin
int B2P = A3; // B2 Pin
// pins for GREEN LEDs
int G1P = A2; // G1 Pin
int G2P = A4; // G2 Pin
int OEP = 5; // OE Pin
int LP = 6; // Latch Pin
int ClkP = 7; // Clock Pin
void setup() {
Serial.begin(115200);
//set pins to output so you can control the shift register
configurePins();
clearBuffer();
add_A();
add_B();
printBuffer();
}
void loop() {
drawBuffer();
}
// configure pins
void configurePins(){
pinMode(R1P, OUTPUT);
pinMode(R2P, OUTPUT);
pinMode(G1P, OUTPUT);
pinMode(G2P, OUTPUT);
pinMode(B1P, OUTPUT);
pinMode(B2P, OUTPUT);
pinMode(AP,OUTPUT);
pinMode(BP,OUTPUT);
pinMode(CP,OUTPUT);
pinMode(OEP,OUTPUT);
pinMode(LP, OUTPUT);
pinMode(ClkP, OUTPUT);
digitalWrite(AP, LOW);
digitalWrite(BP, LOW);
digitalWrite(CP, LOW);
digitalWrite(LP, LOW);
digitalWrite(OEP, LOW);
}
void clearBuffer(){
for (byte i=0;i<16;i++)
buffRed[i] = 0;
}
void add_A(){
uint16_t a[16];
a[ 0] = 0b0000000000000000;
a[ 1] = 0b0000000000000000;
a[ 2] = 0b0000000110000000;
a[ 3] = 0b0000001111000000;
a[ 4] = 0b0000011111100000;
a[ 5] = 0b0000111111110000;
a[ 6] = 0b0001111111111000;
a[ 7] = 0b0011111111111100;
a[ 8] = 0b0011111111111100;
a[ 9] = 0b0011111111111100;
a[10] = 0b0011111111111100;
a[11] = 0b0011111111111100;
a[12] = 0b0011111111111100;
a[13] = 0b0011111111111100;
a[14] = 0b0000000000000000;
a[15] = 0b0000000000000000;
for(byte i = 0; i<16;i++)
buffRed[i] = buffRed[i]<<16 | a[i];
}
void add_B(){
uint16_t a[16];
a[ 0] = 0b0000000000000000;
a[ 1] = 0b0000000000000000;
a[ 2] = 0b0011111111111100;
a[ 3] = 0b0011111111111100;
a[ 4] = 0b0011000000001100;
a[ 5] = 0b0011000000001100;
a[ 6] = 0b0011000000001100;
a[ 7] = 0b0011000000001100;
a[ 8] = 0b0011000000001100;
a[ 9] = 0b0011000000001100;
a[10] = 0b0011000000001100;
a[11] = 0b0011000000001100;
a[12] = 0b0011111111111100;
a[13] = 0b0011111111111100;
a[14] = 0b0000000000000000;
a[15] = 0b0000000000000000;
for(byte i = 0; i<16;i++)
buffRed[i] = buffRed[i]<<16 | a[i];
}
// print content of Buffer array to serial console
void printBuffer(){
uint32_t c;
for(byte r=0;r<16;r++){
c = buffRed[r];
for(byte i=0;i<32;i++){
if (c & 0b10000000000000000000000000000000)
Serial.print("#");
else
Serial.print(".");
c = c << 1;
}
Serial.println();
}
}
// send buffer content to panel (RED LEDs only)
void drawBuffer(){
uint32_t mask;
mask = 0b1;
for(byte row=0; row<8; row++){
for (byte i = 1; i < 33; i++) {
// send RED
digitalWrite(R1P, !!(buffRed[row] & (mask << (32-i))));
digitalWrite(R2P, !!(buffRed[row+8] & (mask << (32-i))));
// send GREEN
digitalWrite(G1P, 0);
digitalWrite(G2P, 0);
// send BLUE
digitalWrite(B1P, 0);
digitalWrite(B2P, 0);
// flash clock to mark data sent
digitalWrite(ClkP, HIGH);
digitalWrite(ClkP, LOW);
}
digitalWrite(OEP, HIGH);
digitalWrite(LP, HIGH);
// select new row
digitalWrite(AP, !!(row & B00000001));
digitalWrite(BP, !!(row & B00000010));
digitalWrite(CP, !!(row & B00000100));
digitalWrite(LP, LOW);
digitalWrite(OEP, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment