#define button 4
uint8_t button_state, button_state_last = 1;
uint8_t led_state = 0;
uint8_t count = 0;
uint64_t time0;
uint16_t ledPin[8] = {16, 17, 5, 18, 19, 21, 22, 23};
uint16_t led_mode[4][9] = {
{0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01, 0x00},
{0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff},
{0xff, 0xe7, 0xc3, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00},
{0xff, 0x7e, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00}
};
void Check_button();
void Counter();
void mode_selecting(uint8_t led_state);
void setup() {
Serial.begin(115200);
Serial.println("Hello, ESP32!");
for (int i = 0; i < 8; ++i)
pinMode(ledPin[i], OUTPUT);
pinMode(button, INPUT);
time0 = millis();
}
void loop() {
Check_button();
Counter();
mode_selecting(led_state);
delay(10);
}
void Check_button() {
button_state = digitalRead(button);
if (button_state == 1 && button_state_last != button_state) {
led_state = (led_state + 1) % 4;
count = 0;
delay(10);
}
button_state_last = button_state;
}
void mode_selecting(uint8_t state) {
uint16_t current_pattern = led_mode[state][count];
for (int i = 0; i < 8; ++i) {
if (current_pattern & (1 << i)) {
digitalWrite(ledPin[i], HIGH);
} else {
digitalWrite(ledPin[i], LOW);
}
}
}
void Counter() {
if (millis() - time0 > 1000) {
time0 = millis();
count = (count + 1) % 9;
}
if(led_state > 1){
if(count==5)
count = 0;
}
}