Skip to content

Instantly share code, notes, and snippets.

@jamesabruce
Created January 22, 2015 17:55
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesabruce/d9856765897b12d6bf38 to your computer and use it in GitHub Desktop.
Save jamesabruce/d9856765897b12d6bf38 to your computer and use it in GitHub Desktop.
Sample code for working with the giant LED screen described at MakeUseOf.com, using Adafruit Neomatrix and GFX libraries
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#define XSIZE 15
#define YSIZE 14
#define PIN 6
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(XSIZE, YSIZE, PIN,
NEO_MATRIX_BOTTOM + NEO_MATRIX_LEFT +
NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG,
NEO_GRB + NEO_KHZ800);
// Some sprite definitions. Use "image to bitmap converter" included with Adafruit GFX library to create these
prog_uint8_t upArrow[] PROGMEM={
0x0,0x0,
0x1,0x0,
0x3,0x80,
0x7,0xc0,
0xf,0xe0,
0x1f,0xf0,
0x3f,0xf8,
0x7f,0xfc,
0xf,0xe0,
0xf,0xe0,
0xf,0xe0,
0xf,0xe0,
0xf,0xe0,
0x0,0x0
};
prog_uint8_t smile[] PROGMEM=
{
0x0,0x0,
0x3,0x80,
0xc,0x60,
0x10,0x10,
0x24,0x48,
0x44,0x44,
0x40,0x4,
0x48,0x24,
0x48,0x24,
0x27,0xc8,
0x10,0x10,
0xc,0x60,
0x3,0x80,
0x0,0x0
};
// Color definitions
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
void setup(){
matrix.begin();
matrix.setTextWrap(false);
matrix.setBrightness(255);
}
int x = matrix.width();
int pass = 0;
void loop(){
// randomize text and bitmap colours
uint16_t bitmapColour = drawRGB24toRGB565(random(0,255),random(0,255),random(0,255));
//display smiley bitmap before message
if(pass == 0) {
pulseBitmap(smile,3,bitmapColour);
uint16_t textColour = drawRGB24toRGB565(random(0,255),random(0,255),random(0,255));
matrix.setTextColor(textColour);
matrix.show();
}
pass++;
matrix.fillScreen(0);
matrix.setBrightness(255);
matrix.setCursor(x, 3);
String message = "MakeUseOf.com";
int messageScrollLength = (message.length())*8;
matrix.print(message);
if(--x < -messageScrollLength) { // number of characters * 8
x = matrix.width();
pass = 0;
}
matrix.show();
delay(100);
}
void pulseBitmap(uint8_t* bmp,int times, uint16_t colour){
for(int x=1;x<=times;x++){
for(int i=0;i<=10;i++){
matrix.setBrightness(i*25);
matrix.drawBitmap(0,0,bmp,15,14,colour);
matrix.show();
delay(20);
}
delay(200);
for(int i=10;i>=0;i--){
matrix.setBrightness(i*25);
matrix.drawBitmap(0,0,bmp,15,14,colour);
matrix.show();
delay(20);
}
}
}
/**************************************************************************/
/*!
@brief Converts a 24-bit RGB color to an equivalent 16-bit RGB565 value
@param[in] r
8-bit red
@param[in] g
8-bit green
@param[in] b
8-bit blue
@section Example
@code
// Get 16-bit equivalent of 24-bit color
uint16_t gray = drawRGB24toRGB565(0x33, 0x33, 0x33);
@endcode
*/
/**************************************************************************/
uint16_t drawRGB24toRGB565(uint8_t r, uint8_t g, uint8_t b)
{
return ((r / 8) << 11) | ((g / 4) << 5) | (b / 8);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment