#include <FastLED.h>
#define PIN 0 // Chân PB0 trên ATtiny85
#define INPUT_PIN 4 // Chân PB4 trên ATtiny85
#define NUM_LEDS 4
CRGB leds[NUM_LEDS];
char* patterns1[] = {"R000","0R00","00R0","000R","0000","000R","00R0","0R00","R000","0000","R000","RR00","RRR0","RRRR","RRR0","RR00","R000","0000","000R","00RR","0RRR","RRRR","0RRR","00RR","000R","0000"}; // Mảng chứa các mô hình màu sắc
char* patterns2[] = {"RRRR", "0000", "RRRR", "0000"}; // Mảng chứa các mô hình màu sắc khác
void setColor(char color, int i) {
switch(color) {
case 'R': // Đỏ
leds[i] = CRGB::Red;
break;
case 'B': // Xanh dương
leds[i] = CRGB::Blue;
break;
case 'G': // Xanh lá cây
leds[i] = CRGB::Green;
break;
case '0': // Tắt
leds[i] = CRGB::Black;
break;
}
}
void setup() {
FastLED.addLeds<NEOPIXEL, PIN>(leds, NUM_LEDS);
pinMode(INPUT_PIN, INPUT); // Đặt chân PB4 làm chân đầu vào
}
void loop() {
int numPatterns1 = sizeof(patterns1) / sizeof(patterns1[0]);
int numPatterns2 = sizeof(patterns2) / sizeof(patterns2[0]);
char** currentPatterns;
int numCurrentPatterns;
while (true) {
if (digitalRead(INPUT_PIN) == HIGH) {
currentPatterns = patterns2;
numCurrentPatterns = numPatterns2;
} else {
currentPatterns = patterns1;
numCurrentPatterns = numPatterns1;
}
for(int p=0; p<numCurrentPatterns; p++) {
char* pattern = currentPatterns[p];
for(int i=0; i<NUM_LEDS; i++) {
setColor(pattern[i], i);
if ((digitalRead(INPUT_PIN) == HIGH && currentPatterns == patterns1) ||
(digitalRead(INPUT_PIN) == LOW && currentPatterns == patterns2)) {
// Nếu trạng thái của INPUT_PIN thay đổi, ngắt vòng lặp for
break;
}
}
FastLED.show();
delay(500);
}
}
}