const int led_pins[8] = {19, 18, 5, 17, 16, 4, 0, 2};
const int on_button = 12;
const int off_button = 14;
bool run = false;
int count = 0;
long ms;
void setup(){
Serial.begin(115200);
Serial.println("hello ESP32!");
pinMode(on_button, INPUT_PULLUP);
pinMode(off_button, INPUT_PULLUP);
for(int i=0;i<8;i++)
{
pinMode(led_pins[i], OUTPUT);
}
}
void loop() {
if (digitalRead(on_button) == 0)
{
run = true;
}
if (digitalRead(off_button) == 0) {
run = false;
all_off();
}
//running led
if (run == true) {
if (millis() - ms >= 1000) {
ms = millis();
all_off();
digitalWrite(led_pins[count++], HIGH);
if (count >= 8) {
count = 0;
}
}
}
}
void all_off()
{
for(int i=0;i<8;i++)
{
digitalWrite(led_pins[i], LOW);
}
}