You are on page 1of 12

Pixel LED Matrix Buddhist Flag | Vesak

මේ වීඩිම ෝ එමේදී මම කි ලා මෙන්මන් ws2811 Pixel LED පාවිච්චි කරලා ලස්සන රටා එේක ම ෞද්ධ
මකාඩි ේ හෙන විදි ගැන . Pixel LED වැඩ කරන විදි ගැන මම ගි අවුරුද්මද් මවසේ වීඩිම ෝ
එමේදී කි ලා දුන්නා. ඒ වීඩිම ෝ එක ැලුමේ නැත්තේ මමතනින් ඒක ලන්න පුලුවන්.
https://nisalhe.com/vesak2019pixel/

මේමකදි මම LED 50 ේ ති න ල්බ් වැල්බ 5 ේ පාවීච්චි කරලා ති නවා. ඒ කි න්මන් ඔේමකාම ල්බ්
250 ේ. ඔ ාලට මේ ගානම මහෝ තවත් ල්බ් වැඩි කරලා උනත් පාවිච්චි කරන්න පුලුවන්. ල්බ් ගාන
මවනස් කරනවානේ පැත්තකට ති න ල්බ් ගානයි උස අතට ති න ල්බ් ගානයි code එමේ මවනස්
කරන්න ඕමන් මේ මේළි මෙමකන්.

const uint8_t mWidth = 10;


const uint8_t mHeight = 25;
ඊට පස්මස මේ විදි ට තමයි ල්බ් වැල්බ ටිේ මසට් කරගන්න ඕමන. වැඩි විස්තර ඔේමකාම වීඩිම ෝ
එමේ කි ලා ති නවා. මේ විදි ට ල්බ් ටික මසට් කලාම අපිට program එක ලි ද්දි ේරශ් න ේ
මවන්මන් ල්බ් වල index එක හරි ටම මහා ාගන්න එක. මමාකෙ මේ ල්බ් ටික සේ න්ධමවලා
තිම න්මන් zig-zag විදි ට. මේ ේරශ්මනට ලස්සන වැඩේ කරලා ති නවා මේ ති න function එමකන්.
මේක ගැන වීඩිම ෝ එමේ කරන පැහැදිලි කිරීම මත්රුේ ගන්න උත්සාහ කරන්න.

uint16_t XY( uint8_t x, uint8_t y) {


uint16_t i;
if ( y & 0x01) {
uint8_t reverseX = (mWidth - 1) - x;
i = (y * mWidth) + reverseX;
} else {
i = (y * mWidth) + x;
}
return i ;
}

හරි ෙැන් තිම න්මන් ඒ function එමකන් return මවන index එකත් use කරමගන අපිට අවශ් pattern
ටික ලි ාගන්න. මේ තිම න්මන් මම ලි පු සේූර්ණ code එක. මේමකදිත් ඉස්මසල්බලා වීඩිම ෝ වල
වමේම pattern ටික function විදි ට ලි ලා loop එමේදී ඒවා අවශ් විදි ට call කරලා ති නවා. තව
pattern ඔ ාලට ලි ාගන්නත් පුලුවන්. අවශ් විදි ට code එක මවනස් කරගන පාවිච්චි කරන්න.

#include <FastLED.h>
#define DATA_PIN 2
const uint8_t mWidth = 10;
const uint8_t mHeight = 25;
const uint8_t NUM_LEDS = mWidth * mHeight;
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
FastLED.setBrightness(100); //0-255
}
void loop() {
flag2(12);
P_2();
flag1Blink(5, 1000);
P_flagColors();
fullFlag(20);
flag3(20);
P_flag();
P_flag();
lineKN(1);
fullFlag(20);
P_flagColors();
}
uint16_t XY( uint8_t x, uint8_t y) {
uint16_t i;
if ( y & 0x01) {
uint8_t reverseX = (mWidth - 1) - x;
i = (y * mWidth) + reverseX;
} else {
i = (y * mWidth) + x;
}
return i ;
}
void clearDown() {
for ( byte y = 0; y < mHeight / 5; y++) {
for ( byte x = 0; x < mWidth; x++) {
leds[ XY(x, y)] = CRGB::Black;
}
}
FastLED.show();
}
void clearUp() {
for ( byte y = 4 * mHeight / 5; y < mHeight; y++) {
for ( byte x = 0; x < mWidth; x++) {
leds[ XY(x, y)] = CRGB::Black;
}
}
FastLED.show();
}
void clearSide() {
for ( byte y = 0; y < mHeight; y++) {
leds[ XY(0, y)] = CRGB::Black;
leds[ XY(9, y)] = CRGB::Black;
}
FastLED.show();
}
void clearAll() {
for ( int x = 0; x < NUM_LEDS; x++) {
leds[ x] = CRGB::Black;
}
FastLED.show();
}
void flag1Blink(int reps, int t) {
for ( int x = 0; x < reps; x++) {
flag1();
delay(t);
clearAll();
delay(t / 2);
}
}
void flag1() {
for ( byte y = 0; y < mHeight / 5; y++) {
for ( byte x = 0; x < mWidth; x++) {
leds[ XY(x, y)] = CRGB::Blue;
}
}
for ( byte y = mHeight / 5; y < 2 * mHeight / 5; y++) {
for ( byte x = 0; x < mWidth; x++) {
leds[ XY(x, y)] = CRGB::Yellow;
}
}
for ( byte y = 2 * mHeight / 5; y < 3 * mHeight / 5; y++) {
for ( byte x = 0; x < mWidth; x++) {
leds[ XY(x, y)] = CRGB::Red;
}
}
for ( byte y = 3 * mHeight / 5; y < 4 * mHeight / 5; y++) {
for ( byte x = 0; x < mWidth; x++) {
leds[ XY(x, y)] = CRGB::White;
}
}
for ( byte y = 4 * mHeight / 5; y < 5 * mHeight / 5; y++) {
for ( byte x = 0; x < mWidth; x++) {
leds[ XY(x, y)] = CRGB::OrangeRed;
}
}
FastLED.show();
}
void flag2(int reps) {
for ( int x = 0; x < reps; x++) {
for (int a = 0; a <= 5 * mWidth; a += mWidth) {
flagInner(a);
clearDown();
}
for (int a = 5 * mWidth; a >= 0; a -= mWidth) {
flagInner(a);
clearUp();
}
}
}
void flagInner(int a) {
for ( byte y = 0; y < mHeight * 4 / 25; y++) {
for ( byte x = 0; x < mWidth; x++) {
leds[ XY(x, y) + a] = CRGB::Blue;
}
}
for ( byte y = mHeight * 4 / 25; y < 2 * mHeight * 4 / 25; y++) {
for ( byte x = 0; x < mWidth; x++) {
leds[ XY(x, y) + a] = CRGB::Yellow;
}
}
for ( byte y = 2 * mHeight * 4 / 25; y < 3 * mHeight * 4 / 25; y++) {
for ( byte x = 0; x < mWidth; x++) {
leds[ XY(x, y) + a] = CRGB::Red;
}
}
for ( byte y = 3 * mHeight * 4 / 25; y < 4 * mHeight * 4 / 25; y++) {
for ( byte x = 0; x < mWidth; x++) {
leds[ XY(x, y) + a] = CRGB::White;
}
}
for ( byte y = 4 * mHeight * 4 / 25; y < 5 * mHeight * 4 / 25; y++) {
for ( byte x = 0; x < mWidth; x++) {
leds[ XY(x, y) + a] = CRGB::OrangeRed;
}
}
FastLED.show();
delay(100);
//clear();
}
void flag3(int reps) {
for ( int x = 0; x < reps; x++) {
flag3_1();
delay(300);
clearSide();
flag3_2();
delay(300);
clearSide();
}
}
void flag3_1() {
for ( byte y = 0; y < mHeight / 5; y++) {
for ( byte x = 0; x < mWidth - 1; x++) {
leds[ XY(x, y)] = CRGB::Blue;
}
}
for ( byte y = mHeight / 5; y < 2 * mHeight / 5; y++) {
for ( byte x = 1; x < mWidth; x++) {
leds[ XY(x, y)] = CRGB::Yellow;
}
}
for ( byte y = 2 * mHeight / 5; y < 3 * mHeight / 5; y++) {
for ( byte x = 0; x < mWidth - 1; x++) {
leds[ XY(x, y)] = CRGB::Red;
}
}
for ( byte y = 3 * mHeight / 5; y < 4 * mHeight / 5; y++) {
for ( byte x = 1; x < mWidth; x++) {
leds[ XY(x, y)] = CRGB::White;
}
}
for ( byte y = 4 * mHeight / 5; y < 5 * mHeight / 5; y++) {
for ( byte x = 0; x < mWidth - 1; x++) {
leds[ XY(x, y)] = CRGB::OrangeRed;
}
}
FastLED.show();
}
void flag3_2() {
for ( byte y = 0; y < mHeight / 5; y++) {
for ( byte x = 1; x < mWidth; x++) {
leds[ XY(x, y)] = CRGB::Blue;
}
}
for ( byte y = mHeight / 5; y < 2 * mHeight / 5; y++) {
for ( byte x = 0; x < mWidth - 1; x++) {
leds[ XY(x, y)] = CRGB::Yellow;
}
}
for ( byte y = 2 * mHeight / 5; y < 3 * mHeight / 5; y++) {
for ( byte x = 1; x < mWidth; x++) {
leds[ XY(x, y)] = CRGB::Red;
}
}
for ( byte y = 3 * mHeight / 5; y < 4 * mHeight / 5; y++) {
for ( byte x = 0; x < mWidth - 1; x++) {
leds[ XY(x, y)] = CRGB::White;
}
}
for ( byte y = 4 * mHeight / 5; y < 5 * mHeight / 5; y++) {
for ( byte x = 1; x < mWidth; x++) {
leds[ XY(x, y)] = CRGB::OrangeRed;
}
}
FastLED.show();
}
void lineKN(int reps) {
for ( int x = 0; x < reps; x++) {
for ( byte y = 0; y < mHeight ; y++) {
for ( byte x = 0; x < mWidth; x++) {
leds[ XY(x, y)] = CRGB::Blue;
}
FastLED.show();
delay(40);
//clearAll();
}
for ( int x = 0; x < reps; x++) {
for ( byte y = 0; y < mHeight ; y++) {
for ( byte x = 0; x < mWidth; x++) {
leds[ XY(x, y)] = CRGB::Magenta;
}
FastLED.show();
delay(40);
//clearAll();
}
}
for ( int x = 0; x < reps; x++) {
for ( byte y = 0; y < mHeight ; y++) {
for ( byte x = 0; x < mWidth; x++) {
leds[ XY(x, y)] = CRGB::Green;
}
FastLED.show();
delay(40);
//clearAll();
}
}
for ( int x = 0; x < reps; x++) {
for ( byte y = 0; y < mHeight ; y++) {
for ( byte x = 0; x < mWidth; x++) {
leds[ XY(x, y)] = CRGB::DarkRed;
}
FastLED.show();
delay(40);
//clearAll();
}
}
for ( int x = 0; x < reps; x++) {
for ( byte y = 0; y < mHeight ; y++) {
for ( byte x = 0; x < mWidth; x++) {
leds[ XY(x, y)] = CRGB::DarkTurquoise;
}
FastLED.show();
delay(40);
//clearAll();
}
}
}
}
void fullFlag(int reps) {
for ( int x = 0; x < reps; x++) {
for ( byte y = 5 * mHeight * 4 / 25; y < mHeight - 1 ; y++) {
for ( byte x = 0; x < mWidth / 5; x++) {
leds[ XY(x, y)] = CRGB::Blue;
}
}
for ( byte y = 5 * mHeight * 4 / 25; y < mHeight - 1 ; y++) {
for ( byte x = mWidth / 5; x < 2 * mWidth / 5; x++) {
leds[ XY(x, y)] = CRGB::Yellow;
}
}
for ( byte y = 5 * mHeight * 4 / 25; y < mHeight - 1 ; y++) {
for ( byte x = 2 * mWidth / 5; x < 3 * mWidth / 5; x++) {
leds[ XY(x, y)] = CRGB::Red;
}
}
for ( byte y = 5 * mHeight * 4 / 25; y < mHeight - 1 ; y++) {
for ( byte x = 3 * mWidth / 5; x < 4 * mWidth / 5; x++) {
leds[ XY(x, y)] = CRGB::White;
}
}
for ( byte y = 5 * mHeight * 4 / 25; y < mHeight - 1 ; y++) {
for ( byte x = 4 * mWidth / 5; x < 5 * mWidth / 5; x++) {
leds[ XY(x, y)] = CRGB::OrangeRed;
}
}
FastLED.show();
fullFlagInner(0);
clearDown();
for ( byte y = 5 * mHeight * 4 / 25 + 1; y < mHeight ; y++) {
for ( byte x = 0; x < mWidth / 5; x++) {
leds[ XY(x, y)] = CRGB::Blue;
}
}
for ( byte y = 5 * mHeight * 4 / 25 + 1; y < mHeight ; y++) {
for ( byte x = mWidth / 5; x < 2 * mWidth / 5; x++) {
leds[ XY(x, y)] = CRGB::Yellow;
}
}
for ( byte y = 5 * mHeight * 4 / 25 + 1; y < mHeight ; y++) {
for ( byte x = 2 * mWidth / 5; x < 3 * mWidth / 5; x++) {
leds[ XY(x, y)] = CRGB::Red;
}
}
for ( byte y = 5 * mHeight * 4 / 25 + 1; y < mHeight ; y++) {
for ( byte x = 3 * mWidth / 5; x < 4 * mWidth / 5; x++) {
leds[ XY(x, y)] = CRGB::White;
}
}
for ( byte y = 5 * mHeight * 4 / 25 + 1; y < mHeight ; y++) {
for ( byte x = 4 * mWidth / 5; x < 5 * mWidth / 5; x++) {
leds[ XY(x, y)] = CRGB::OrangeRed;
}
}
FastLED.show();
fullFlagInner(10);
clearUp();
}
}
void fullFlagInner(int a) {
for ( byte y = 0; y < mHeight * 4 / 25; y++) {
for ( byte x = 0; x < mWidth; x++) {
leds[ XY(x, y) + a] = CRGB::Blue;
}
}
for ( byte y = mHeight * 4 / 25; y < 2 * mHeight * 4 / 25; y++) {
for ( byte x = 0; x < mWidth; x++) {
leds[ XY(x, y) + a] = CRGB::Yellow;
}
}
for ( byte y = 2 * mHeight * 4 / 25; y < 3 * mHeight * 4 / 25; y++) {
for ( byte x = 0; x < mWidth; x++) {
leds[ XY(x, y) + a] = CRGB::Red;
}
}
for ( byte y = 3 * mHeight * 4 / 25; y < 4 * mHeight * 4 / 25; y++) {
for ( byte x = 0; x < mWidth; x++) {
leds[ XY(x, y) + a] = CRGB::White;
}
}
for ( byte y = 4 * mHeight * 4 / 25; y < 5 * mHeight * 4 / 25; y++) {
for ( byte x = 0; x < mWidth; x++) {
leds[ XY(x, y) + a] = CRGB::OrangeRed;
}
}
FastLED.show();
delay(400);
}
///*********************************************************
void P_flag() {
int TIME_1 = 8;
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB::OrangeRed;
FastLED.show();
delay(TIME_1);
}
for (int i = 0; i < 4 * NUM_LEDS / 5; i++) {
leds[i] = CRGB::White;
FastLED.show();
delay(TIME_1);
}
for (int i = 0; i < 3 * NUM_LEDS / 5; i++) {
leds[i] = CRGB::Red;
FastLED.show();
delay(TIME_1);
}
for (int i = 0; i < 2 * NUM_LEDS / 5; i++) {
leds[i] = CRGB::Gold;
FastLED.show();
delay(2*TIME_1);
}
for (int i = 0; i < NUM_LEDS / 5; i++) {
leds[i] = CRGB::Blue;
FastLED.show();
delay(3*TIME_1);
}
delay(4000);
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB::Black;
FastLED.show();
delay(0);
}
}
void P_2() {
for (int i = 31; i < NUM_LEDS; i++) {
leds[i] = CRGB::Red;
leds[i - 1] = CRGB::Red;
leds[i - 30] = CRGB::Blue;
FastLED.show();
delay(10);
}
for (int i = NUM_LEDS; i >= 30; i--) {
leds[i-30] = CRGB::Purple;
leds[i] = CRGB::White;
delay(10);
FastLED.show();
}
}
void P_flagColors() {
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB::Blue;
}
FastLED.show();
delay(1000);
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB::Yellow;
}
FastLED.show();
delay(1000);
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB::Red;
}
FastLED.show();
delay(1000);
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB::White;
}
FastLED.show();
delay(1000);
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB::OrangeRed;
}
FastLED.show();
delay(1000);
}

You might also like