මේ වීඩියෝ එකේදී මම කියලා දෙන්නේ 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);
}
