mdraber
Published © GPL3+

How to control 32x8 WS2812 LED Matrix with Arduino PART2

Displaying bitmaps Using different color schemes

IntermediateFull instructions provided2 hours2,351
How to control 32x8 WS2812 LED Matrix with Arduino PART2

Story

Read more

Code

Code to display 8x8 bitmap using CRGB color scheme

Arduino
#include <FastLED.h>
#define NUM_LEDS 256
#define DATA_PIN 12
CRGB leds[NUM_LEDS];

void setup() {   
 FastLED.addLeds<WS2812,DATA_PIN,RGB>(leds,NUM_LEDS);
 FastLED.setBrightness(150);
}

void loop() {  

  for (int j=0;j<8;j++)
   for (int i=0;i<8;i++){
    if (j&1) 				//odd column
      leds[j*8+7-i]=Snake[i][j];
    else     				//even column
      leds[j*8+i-1]=Snake[i][j];
    delay(50);
    FastLED.show();
  }
}

Displaying text Arduino colored using various colors from HSV color scheme

Arduino
#include <FastLED.h>
#define NUM_LEDS 256
#define DATA_PIN 12
CRGB leds[NUM_LEDS];

void setup() {   
 FastLED.addLeds<WS2812,DATA_PIN,RGB>(leds,NUM_LEDS);
 FastLED.setBrightness(150);
}


int Arduino [8][32]{
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 111, 128, 0, 0, 0, 0, 0, 0, 0, 96, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 160, 0, 0, 0},
{96, 0, 0, 135, 0, 0, 0, 0, 0, 0, 96, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 178, 0, 0},
{96, 0, 0, 135, 0, 0, 0, 0, 0, 0, 96, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 135, 0, 0, 192, 0},
{96, 111, 128, 135, 0, 160, 178, 0, 192, 210, 96, 0, 111, 0, 135, 0, 160, 0, 178, 192, 210, 0, 96, 111, 128, 0, 0, 0, 0, 0, 192, 0},
{96, 0, 0, 135, 0, 160, 0, 0, 192, 0, 96, 0, 111, 0, 135, 0, 160, 0, 178, 0, 210, 0, 96, 0, 128, 0, 0, 135, 0, 0, 192, 0},
{96, 0, 0, 135, 0, 160, 0, 0, 192, 210, 96, 0, 111, 128, 135, 0, 160, 0, 178, 0, 210, 0, 96, 111, 128, 0, 0, 0, 0, 178, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 160, 0, 0, 0},
};

void loop() {  
  for (int j=0;j<32;j++)
    for (int i=0;i<8;i++){
      if (!(j&1)and Arduino[i][j]==0) leds[j*8+i]=CRGB(0,0,0);
      if (!(j&1)and Arduino[i][j]!=0) leds[j*8+i]=CHSV(Arduino[i][j],255,255);
      if (j&1 and  Arduino[i][j]==0 ) leds[j*8+7-i]=CRGB(0,0,0);
      if (j&1 and  Arduino[i][j]!=0 ) leds[j*8+7-i]=CHSV(Arduino[i][j],255,255);
    delay(20);
    FastLED.show();
  }
}

Displaying text Arduino using single color or randomly generated colors from the HSV color scheme

Arduino
#include <FastLED.h>
#define NUM_LEDS 256
#define DATA_PIN 12
CRGB leds[NUM_LEDS];

void setup() {   
 FastLED.addLeds<WS2812,DATA_PIN,RGB>(leds,NUM_LEDS);
 FastLED.setBrightness(150);
}

int Arduino [32][8]{
 
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
{1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
{1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0},
{1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0},
{1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0},
{1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0},
};

void loop() { 
  for (int j=0;j<32;j++)
    for (int i=0;i<8;i++){
      if (!(j&1) and Arduino[i][j]==1) leds[j*8+i]=CHSV(0,255,255);
      if (j&1 and Arduino[i][j]==1) leds[j*8+7-i]=CHSV(0,255,255);
      //replace the two lines above with these two  to use Random HSV colors
      //if (!(j&1) and Arduino[i][j]==1) leds[j*8+i]=CHSV(random(256),255,255);
      //if (j&1 and Arduino[i][j]==1) leds[j*8+7-i]=CHSV(random(256),255,255);

      FastLED.show();
      delay(50);
    }
}

Credits

mdraber

mdraber

49 projects • 67 followers

Comments