Created
January 7, 2016 21:12
-
-
Save lmaresz/c51947e44743f0051c8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "FastLED.h" | |
#define NUM_LEDS 128 | |
const int dataline = 4; | |
CRGB leds[NUM_LEDS]; | |
int array[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; | |
int arraytemp[16] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; | |
int i,j,k,r; | |
void coloumn(uint8_t x, int value) { | |
if (value < 5) { | |
for (uint8_t y = 0; y < value; y++){ | |
leds[XY(x,y)] = CRGB::Green; | |
} | |
FastLED.show(); | |
for (uint8_t y = 0; y < value; y++){ | |
leds[XY(x,y)] = CRGB::Black; | |
} | |
} | |
else { | |
if (value < 8) { | |
for (uint8_t y = 0; y < 5; y++){ | |
leds[XY(x,y)] = CRGB::Green; | |
} | |
for (uint8_t y = 5; y < value; y++){ | |
leds[XY(x,y)] = CRGB::Orange; | |
} | |
FastLED.show(); | |
for (uint8_t y = 0; y < value; y++){ | |
leds[XY(x,y)] = CRGB::Black; | |
} | |
} | |
else { | |
for (uint8_t y = 0; y < 5; y++){ | |
leds[XY(x,y)] = CRGB::Green; | |
} | |
for (uint8_t y = 5; y < 8; y++){ | |
leds[XY(x,y)] = CRGB::Orange; | |
} | |
leds[XY(x,8)] = CRGB::Red; | |
FastLED.show(); | |
for (uint8_t y = 0; y < value; y++){ | |
leds[XY(x,y)] = CRGB::Black; | |
} | |
} | |
} | |
} | |
int XY(int x, int y) { | |
int matrix[8][16]; | |
int szam = 0; | |
int sor = 0; | |
for (int i = 0; i < 4; i++){ | |
int f_szam = szam + 15; | |
for (int j = 0; j < 16; j++){ | |
matrix[sor][j] = f_szam; | |
f_szam--; | |
} | |
sor++; | |
szam = szam + 16; | |
for (int j = 0; j < 16; j++){ | |
matrix[sor][j] = szam; | |
szam++; | |
} | |
sor++; | |
} | |
return matrix[y][x]; | |
} | |
void setup() { | |
Serial.begin(500000); | |
LEDS.addLeds<PL9823, dataline>(leds, NUM_LEDS); | |
for (int p=0;p< NUM_LEDS;p++){ | |
leds[p] = CRGB::Black; | |
FastLED.show(); | |
} | |
} | |
void loop(){ | |
//protocol expects data in format of 17 bytes | |
//(xff) as a marker to ensure proper synchronization always | |
/*if (!Serial.available()>=17) { | |
for(r=0; r<17; r++) | |
array[r]=0; | |
} | |
*/ | |
if(Serial.read() == 0xff){ | |
for(i=0; i<16; i++){ | |
array[i] = Serial.read(); | |
} | |
//switch case statement | |
for(j=0; j<16; j++){ | |
if(array[j]!= arraytemp[j]){ | |
switch (array[j]) { | |
case 0: | |
coloumn(j,0); | |
break; | |
case 1: | |
coloumn(j,1); | |
break; | |
case 2: | |
coloumn(j,2); | |
break; | |
case 3: | |
coloumn(j,3); | |
break; | |
case 4: | |
coloumn(j,4); | |
break; | |
case 5: | |
coloumn(j,5); | |
break; | |
case 6: | |
coloumn(j,6); | |
break; | |
case 7: | |
coloumn(j,7); | |
break; | |
case 8: | |
coloumn(j,8); | |
break; | |
} | |
arraytemp[j] = array[j]; | |
} | |
} | |
} | |
delay(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment