#include <FastLED.h>
#include <string.h>
#include <time.h>
#define LED_PIN 2
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
#define NUM_LEDS 16 * 9
CRGB leds[NUM_LEDS];
#define NUM_COLS 16
#define NUM_ROWS 9
CRGB xyleds[NUM_ROWS][NUM_COLS];
//PALETTE
DEFINE_GRADIENT_PALETTE( greenblue_gp ) {
0, 0, 194, 255, //light blue
46, 3, 0, 246, //dark blue
176, 55, 222, 70, //bright green
255, 0, 194, 255 //light blue
};
DEFINE_GRADIENT_PALETTE( orangepink_gp ) {
0, 255, 100, 0, //orange
90, 255, 0, 255, //magenta
150, 255, 100, 0, //orange
255, 255, 100, 0 //orange
};
DEFINE_GRADIENT_PALETTE( browngreen_gp ) {
0, 6, 255, 0, //green
71, 0, 255, 153, //bluegreen
122, 200, 200, 200, //gray
181, 110, 61, 6, //brown
255, 6, 255, 0 //green
};
FL_PROGMEM TProgmemRGBGradientPalettePtr const palettes[] = {
greenblue_gp,
orangepink_gp,
browngreen_gp,
Rainbow_gp
};
size_t const sz_palettes = sizeof(palettes) / sizeof(*palettes);
// two palettes to hold expanded gradient palettes, to be blended between
// set the B palette to the Rainbow palette, to fade in at power up
CRGBPalette16 palA, palB = palettes[sz_palettes - 1];
void setup() {
FastLED.addLeds<LED_TYPE,LED_PIN,COLOR_ORDER>(leds, NUM_LEDS);
Serial.begin(115200); // Any baud rate should work
Serial.println("Hello Arduino\n");
}
// return a random number which is different each time
uint8_t choose(uint8_t const choices) {
static uint8_t last_choice = 0;
uint8_t res;
do {
res = random8(choices);
} while (res == last_choice);
last_choice = res;
return res;
}
uint8_t hue = 10;
static int cLED = 0;
int NUMBER_0_5_3[5][3] = {
{1, 1, 1},
{1, 0, 1},
{1, 0, 1},
{1, 0, 1},
{1, 1, 1}
};
int NUMBER_1_5_3[5][3] = {
{0, 1, 0},
{0, 1, 0},
{0, 1, 0},
{0, 1, 0},
{0, 1, 0}
};
int NUMBER_2_5_3[5][3] = {
{1, 1, 1},
{0, 0, 1},
{1, 1, 1},
{1, 0, 0},
{1, 1, 1}
};
int NUMBER_3_5_3[5][3] = {
{1, 1, 1},
{0, 0, 1},
{1, 1, 1},
{0, 0, 1},
{1, 1, 1}
};
int NUMBER_4_5_3[5][3] = {
{1, 0, 0},
{1, 0, 0},
{1, 1, 1},
{0, 0, 1},
{0, 0, 1}
};
int NUMBER_5_5_3[5][3] = {
{1, 1, 1},
{1, 0, 0},
{1, 1, 1},
{0, 0, 1},
{1, 1, 1}
};
int NUMBER_6_5_3[5][3] = {
{1, 0, 0},
{1, 0, 0},
{1, 1, 1},
{1, 0, 1},
{1, 1, 1}
};
int NUMBER_7_5_3[5][3] = {
{1, 1, 1},
{0, 0, 1},
{0, 0, 1},
{0, 0, 1},
{0, 0, 1}
};
int NUMBER_8_5_3[5][3] = {
{1, 1, 1},
{1, 0, 1},
{1, 1, 1},
{1, 0, 1},
{1, 1, 1}
};
int NUMBER_9_5_3[5][3] = {
{1, 1, 1},
{1, 0, 1},
{1, 1, 1},
{0, 0, 1},
{1, 1, 1}
};
int NUMBER_colon_5_1[5][1] = {
{0},
{1},
{0},
{1},
{0}
};
int NUMBER_dot_5_2[5][2] = {
{0, 0},
{0, 0},
{1, 1},
{1, 1},
{0, 0}
};
int input = 2;
void loop() {
countDown();
} // loop()
void runningText() {
// 1) Get input string size
// 2) create a massive int array where size = base + total string size in terms of matrix
// 3) start imposing each char on the scrolling text base.
// 4) start a loop to read from the scrolling text matrix base
String inputString = "1";
int scrollingX = 16 + 4; // 4 for 1 char
int scrollingY = 9;
int scrollingXY[scrollingY][scrollingX];
imposeABintoXYUsingOffset( NUMBER_1_5_3, rowOffSet, colOffSet );
}
void timeHHMM() {
char temp[2];
int colOffSet = 2;
int hh = 55;
int mm = 22;
time_t rawtime;
struct tm * timeinfo;
time(&rawtime);
timeinfo = localtime(&rawtime);
Serial.println( timeinfo->tm_sec);
clearAll();
sprintf((char*)temp,"%02u", hh);
colOffSet = 2;
for ( int a = 0; a <= 1; a++) {
colOffSet = colOffSet + ( a * 3);
printNumberOnBaseXY( temp[a], 2, colOffSet);
} // for
colOffSet = colOffSet + 3;
imposeABintoXYUsingOffsetDot( NUMBER_dot_5_2, 3, colOffSet);
colOffSet = colOffSet + 2;
sprintf((char*)temp,"%02u", mm);
for ( int a = 0; a <= 1; a++) {
colOffSet = colOffSet + ( a * 3);
printNumberOnBaseXY( temp[a], 2, colOffSet);
} // for
convertXYtoX();
FastLED.show();
delay( 1000);
} // function
void printNumberOnBaseXY( char iChar, int rowOffSet, int colOffSet) {
if ( iChar == '0') {
imposeABintoXYUsingOffset( NUMBER_0_5_3, rowOffSet, colOffSet);
}
if ( iChar == '1') {
imposeABintoXYUsingOffset( NUMBER_1_5_3, rowOffSet, colOffSet );
}
if ( iChar == '2') {
imposeABintoXYUsingOffset( NUMBER_2_5_3, rowOffSet, colOffSet);
}
if ( iChar == '3') {
imposeABintoXYUsingOffset( NUMBER_3_5_3, rowOffSet, colOffSet);
}
if ( iChar == '4') {
imposeABintoXYUsingOffset( NUMBER_4_5_3, rowOffSet, colOffSet);
}
if ( iChar == '5') {
imposeABintoXYUsingOffset( NUMBER_5_5_3, rowOffSet, colOffSet);
}
if ( iChar == '6') {
imposeABintoXYUsingOffset( NUMBER_6_5_3, rowOffSet, colOffSet);
}
if ( iChar == '7') {
imposeABintoXYUsingOffset( NUMBER_7_5_3, rowOffSet, colOffSet);
}
if ( iChar == '8') {
imposeABintoXYUsingOffset( NUMBER_8_5_3, rowOffSet, colOffSet);
}
if ( iChar == '9') {
imposeABintoXYUsingOffset( NUMBER_9_5_3, rowOffSet, colOffSet);
}
} // function
void countDown() {
char temp[2];
int offSet = 5;
for( int x = 12; x >=0 ; x--) {
clearAll();
sprintf((char*)temp,"%02u",x);
offSet = 5;
for ( int a = 0; a <= 1; a++) {
offSet = offSet + ( a * 4);
if ( temp[a] == '0') {
imposeABintoXYUsingOffset( NUMBER_0_5_3, 3, offSet);
}
if ( temp[a] == '1') {
imposeABintoXYUsingOffset( NUMBER_1_5_3, 3, offSet );
}
if ( temp[a] == '2') {
imposeABintoXYUsingOffset( NUMBER_2_5_3, 3, offSet);
}
if ( temp[a] == '3') {
imposeABintoXYUsingOffset( NUMBER_3_5_3, 3, offSet);
}
if ( temp[a] == '4') {
imposeABintoXYUsingOffset( NUMBER_4_5_3, 3, offSet);
}
if ( temp[a] == '5') {
imposeABintoXYUsingOffset( NUMBER_5_5_3, 3, offSet);
}
if ( temp[a] == '6') {
imposeABintoXYUsingOffset( NUMBER_6_5_3, 3, offSet);
}
if ( temp[a] == '7') {
imposeABintoXYUsingOffset( NUMBER_7_5_3, 3, offSet);
}
if ( temp[a] == '8') {
imposeABintoXYUsingOffset( NUMBER_8_5_3, 3, offSet);
}
if ( temp[a] == '9') {
imposeABintoXYUsingOffset( NUMBER_9_5_3, 3, offSet);
}
} // for
// imposeABintoXYUsingOffsetColon( NUMBER_colon_5_1, 3, offSet + 4);
imposeABintoXYUsingOffsetDot( NUMBER_dot_5_2, 3, offSet + 4);
convertXYtoX();
FastLED.show();
delay( 1000);
} // for
}
void runNumbers() {
for( int x = 0; x <= 9; x++) {
clearAll();
imposeABintoXYUsingOffset( NUMBER_0_5_3, 3, 5);
if ( x == 0) {
imposeABintoXYUsingOffset( NUMBER_0_5_3, 3, 9);
}
if ( x == 1) {
imposeABintoXYUsingOffset( NUMBER_1_5_3, 3, 9);
}
if ( x == 2) {
imposeABintoXYUsingOffset( NUMBER_2_5_3, 3, 9);
}
if ( x == 3) {
imposeABintoXYUsingOffset( NUMBER_3_5_3, 3, 9);
}
if ( x == 4) {
imposeABintoXYUsingOffset( NUMBER_4_5_3, 3, 9);
}
if ( x == 5) {
imposeABintoXYUsingOffset( NUMBER_5_5_3, 3, 9);
}
if ( x == 6 ) {
imposeABintoXYUsingOffset( NUMBER_6_5_3, 3, 9);
}
if ( x == 7) {
imposeABintoXYUsingOffset( NUMBER_7_5_3, 3, 9);
}
if ( x == 8) {
imposeABintoXYUsingOffset( NUMBER_8_5_3, 3, 9);
}
if ( x == 9) {
imposeABintoXYUsingOffset( NUMBER_9_5_3, 3, 9);
}
convertXYtoX();
FastLED.show();
delay( 1000);
} // for
}
void clearAll() {
FastLED.clear();
delay( 10);
cleanXY();
}
void imposeABintoXYUsingOffsetDot( int iNumber[5][2], int rowOffset, int colOffset) {
int baseRowOffset = rowOffset - 1;
int baseColOffset = colOffset - 1;
int sourceColumns = 2;
int sourceRows = 5;
int offsetX;
int offsetY;
int lPosition;
for( int a = 0; a < sourceRows; a++) {
for ( int b = 0; b < sourceColumns; b++) {
offsetX = ( a + baseRowOffset);
offsetY = ( b + baseColOffset);
if ( iNumber[a][b] == 1) {
xyleds[ offsetX][offsetY] = CRGB::CRGB::Blue;
} // if
} // for
} // for
} // function
void imposeABintoXYUsingOffsetColon( int iNumber[5][1], int rowOffset, int colOffset) {
int baseRowOffset = rowOffset - 1;
int baseColOffset = colOffset - 1;
int sourceColumns = 1;
int sourceRows = 5;
int offsetX;
int offsetY;
int lPosition;
for( int a = 0; a < sourceRows; a++) {
for ( int b = 0; b < sourceColumns; b++) {
offsetX = ( a + baseRowOffset);
offsetY = ( b + baseColOffset);
if ( iNumber[a][b] == 1) {
xyleds[ offsetX][offsetY] = CRGB::White;
} // if
} // for
} // for
} // function
void imposeABintoXYUsingOffset( int iNumber[5][3], int rowOffset, int colOffset) {
int baseRowOffset = rowOffset - 1;
int baseColOffset = colOffset - 1;
int sourceColumns = 3;
int sourceRows = 5;
int offsetX;
int offsetY;
int lPosition;
for( int a = 0; a < sourceRows; a++) {
for ( int b = 0; b < sourceColumns; b++) {
offsetX = ( a + baseRowOffset);
offsetY = ( b + baseColOffset);
if ( iNumber[a][b] == 1) {
xyleds[ offsetX][offsetY] = CRGB::White;
} // if
} // for
} // for
} // function
void convertXYtoX( ) {
int lposition = 0;
for( int x = 0; x < NUM_ROWS; x++) {
for ( int y = 0; y < NUM_COLS; y++) {
lposition = ( x * NUM_COLS) + y;
leds[lposition] = xyleds[x][y];
} // for
} // for
}
void cleanXY() {
for( int x = 0; x < NUM_ROWS; x++) {
for ( int y = 0; y < NUM_COLS; y++) {
xyleds[x][y] = CRGB::Black;
} // for
} // for
} // for
void faceDisplay() {
leds[0] = CRGB(0, 0, 0);
leds[1] = CRGB(0, 0, 0);
leds[2] = CRGB(0, 0, 0);
leds[3] = CRGB(0, 0, 0);
leds[4] = CRGB(0, 0, 0);
leds[5] = CRGB(255, 0, 0);
leds[6] = CRGB(255, 0, 0);
leds[7] = CRGB(255, 0, 0);
leds[8] = CRGB(0, 0, 0);
leds[9] = CRGB(255, 0, 0);
leds[10] = CRGB(255, 0, 0);
leds[11] = CRGB(255, 0, 0);
leds[12] = CRGB(0, 0, 0);
leds[13] = CRGB(255, 0, 0);
leds[14] = CRGB(0, 0, 0);
leds[15] = CRGB(255, 0, 0);
leds[16] = CRGB(0, 0, 0);
leds[17] = CRGB(255, 0, 0);
leds[18] = CRGB(0, 0, 0);
leds[19] = CRGB(255, 0, 0);
leds[20] = CRGB(0, 0, 0);
leds[21] = CRGB(255, 0, 0);
leds[22] = CRGB(255, 0, 0);
leds[23] = CRGB(255, 0, 0);
leds[24] = CRGB(0, 0, 0);
leds[25] = CRGB(255, 0, 0);
leds[26] = CRGB(0, 0, 0);
leds[27] = CRGB(255, 0, 0);
leds[28] = CRGB(0, 0, 0);
leds[29] = CRGB(0, 0, 0);
leds[30] = CRGB(0, 0, 0);
leds[31] = CRGB(0, 0, 0);
leds[32] = CRGB(0, 0, 0);
leds[33] = CRGB(255, 0, 0);
leds[34] = CRGB(0, 0, 0);
leds[35] = CRGB(255, 0, 0);
leds[36] = CRGB(0, 0, 0);
leds[37] = CRGB(0, 0, 0);
leds[38] = CRGB(0, 0, 0);
leds[39] = CRGB(0, 0, 0);
leds[40] = CRGB(0, 0, 0);
leds[41] = CRGB(255, 0, 0);
leds[42] = CRGB(0, 0, 0);
leds[43] = CRGB(255, 0, 0);
leds[44] = CRGB(0, 0, 0);
leds[45] = CRGB(255, 0, 0);
leds[46] = CRGB(255, 0, 0);
leds[47] = CRGB(255, 0, 0);
leds[48] = CRGB(0, 0, 0);
leds[49] = CRGB(255, 0, 0);
leds[50] = CRGB(255, 0, 0);
leds[51] = CRGB(255, 0, 0);
leds[52] = CRGB(0, 0, 0);
leds[53] = CRGB(255, 0, 0);
leds[54] = CRGB(0, 0, 0);
leds[55] = CRGB(255, 0, 0);
leds[56] = CRGB(0, 0, 0);
leds[57] = CRGB(0, 0, 0);
leds[58] = CRGB(0, 0, 0);
leds[59] = CRGB(0, 0, 0);
leds[60] = CRGB(0, 0, 0);
leds[61] = CRGB(255, 0, 0);
leds[62] = CRGB(255, 0, 0);
leds[63] = CRGB(255, 0, 0);
FastLED.show();
delay(500);
leds[0] = CRGB(0, 0, 0);
leds[1] = CRGB(0, 0, 0);
leds[2] = CRGB(0, 0, 0);
leds[3] = CRGB(0, 0, 0);
leds[4] = CRGB(0, 0, 0);
leds[5] = CRGB(255, 0, 0);
leds[6] = CRGB(255, 0, 0);
leds[7] = CRGB(255, 0, 0);
leds[8] = CRGB(0, 0, 0);
leds[9] = CRGB(0, 0, 0);
leds[10] = CRGB(255, 0, 0);
leds[11] = CRGB(0, 0, 0);
leds[12] = CRGB(0, 0, 0);
leds[13] = CRGB(255, 0, 0);
leds[14] = CRGB(0, 0, 0);
leds[15] = CRGB(255, 0, 0);
leds[16] = CRGB(0, 0, 0);
leds[17] = CRGB(0, 0, 0);
leds[18] = CRGB(255, 0, 0);
leds[19] = CRGB(0, 0, 0);
leds[20] = CRGB(0, 0, 0);
leds[21] = CRGB(255, 0, 0);
leds[22] = CRGB(255, 0, 0);
leds[23] = CRGB(255, 0, 0);
leds[24] = CRGB(0, 0, 0);
leds[25] = CRGB(0, 0, 0);
leds[26] = CRGB(255, 0, 0);
leds[27] = CRGB(0, 0, 0);
leds[28] = CRGB(0, 0, 0);
leds[29] = CRGB(0, 0, 0);
leds[30] = CRGB(0, 0, 0);
leds[31] = CRGB(0, 0, 0);
leds[32] = CRGB(0, 0, 0);
leds[33] = CRGB(0, 0, 0);
leds[34] = CRGB(255, 0, 0);
leds[35] = CRGB(0, 0, 0);
leds[36] = CRGB(0, 0, 0);
leds[37] = CRGB(0, 0, 0);
leds[38] = CRGB(0, 0, 0);
leds[39] = CRGB(0, 0, 0);
leds[40] = CRGB(0, 0, 0);
leds[41] = CRGB(0, 0, 0);
leds[42] = CRGB(255, 0, 0);
leds[43] = CRGB(0, 0, 0);
leds[44] = CRGB(0, 0, 0);
leds[45] = CRGB(255, 0, 0);
leds[46] = CRGB(255, 0, 0);
leds[47] = CRGB(255, 0, 0);
leds[48] = CRGB(0, 0, 0);
leds[49] = CRGB(0, 0, 0);
leds[50] = CRGB(255, 0, 0);
leds[51] = CRGB(0, 0, 0);
leds[52] = CRGB(0, 0, 0);
leds[53] = CRGB(255, 0, 0);
leds[54] = CRGB(0, 0, 0);
leds[55] = CRGB(255, 0, 0);
leds[56] = CRGB(0, 0, 0);
leds[57] = CRGB(0, 0, 0);
leds[58] = CRGB(0, 0, 0);
leds[59] = CRGB(0, 0, 0);
leds[60] = CRGB(0, 0, 0);
leds[61] = CRGB(255, 0, 0);
leds[62] = CRGB(255, 0, 0);
leds[63] = CRGB(255, 0, 0);
FastLED.show();
delay(500);
}
int kMatrixWidth = 16;
int kMatrixHeight = 9;
int bpm = 10;
void pulsingMinimalist() {
int x0 = kMatrixWidth/2;
int y0 = kMatrixHeight/2;
int radius = beatsin8(bpm/2, 0, kMatrixHeight/2);
int x = radius;
int y = 0;
int decisionOver2 = 1 - x; // Decision criterion divided by 2 evaluated at x=r, y=0
int colorHue = beatsin8(bpm*2, 107, 167);
CRGB color1 = CRGB::Blue;
if (radius < 1) {
uint8_t blurAmount = beatsin8(bpm/4,13,50);
blur2d(leds, kMatrixWidth, kMatrixHeight, blurAmount);
}
while(x >= y)
{
uint8_t ms = millis();
leds[XY(x + x0, y + y0)] += color1;
leds[XY( y + x0, x + y0)] += color1;
leds[XY (-x + x0, y + y0)] += color1;
leds[XY(-y + x0, x + y0)] += color1;
leds[XY(-x + x0, -y + y0)] += color1;
leds[XY(-y + x0, -x + y0)] += color1;
leds[XY( x + x0, -y + y0)] += color1;
leds[XY( y + x0, -x + y0)] += color1;
y++;
if (decisionOver2<=0)
{
decisionOver2 += 2 * y + 1; // Change in decision criterion for y -> y+1
}
else
{
x--;
decisionOver2 += 2 * (y - x) + 1; // Change for y -> y+1, x -> x-1
}
} // while
FastLED.show();
for(int j = 0; j < NUM_LEDS; j++) {
leds[j].fadeToBlackBy(30);
} // for
} // function()
int XY( int x, int y) {
return ( x * 16) + y;
}
void runThruEachLED() {
leds[cLED] = CHSV( 100, 255, 200);
cLED++;
if ( cLED >= NUM_LEDS) {
cLED = 0;
}
FastLED.show();
delay( 100);
FastLED.clear();
}
void randomLEDs() {
for ( int i = 0; i < NUM_LEDS; i++) {
leds[i] = CHSV( hue * i, 255, 200);
}
EVERY_N_MILLISECONDS( 15) {
hue++;
}
FastLED.show();
delay( 100);
FastLED.clear();
}
void origMethod() {
static uint8_t k1 = 0; // the amount to blend [0-255]
uint8_t const blendRate = 20; // How fast to blend. Higher is slower. [milliseconds]
EVERY_N_MILLISECONDS(blendRate) {
k1++; // advance the blend
if (k1 == 0) { // overflowed from 255 -> 0, so the blend is complete
// copy B -> A and expand a different gradient palette into palette B
palA = palB;
uint8_t choice = choose(sz_palettes - 1); // -1 avoids picking Rainbow again
palB = (TProgmemRGBGradientPalettePtr) FL_PGM_READ_WORD_NEAR(&palettes[choice]);
}
CRGB *led = leds;
// for each strip
for (uint8_t i = 0; i < 9; i++) {
// select the two palette colours to be blended
CRGB colA = ColorFromPalette(palA, i * 255 / 7);
CRGB colB = ColorFromPalette(palB, i * 255 / 7);
// use linear interpolation to fade between them
colB = colA.lerp8(colB, k1);
// set each of the 10 LEDs on this strip
for (uint8_t j = 0; j < 16; j++)
*led++ = colB;
}
FastLED.show();
}
}