//Array LED untuk lantai 1-5
static const int pin_arr[5] = {2, 0, 4, 16, 17};
//Array untuk button LED
static const int btn_arr[5] = {25, 33, 32, 35, 34};
//Array state of LEDs
static bool ledstates[5] = {false};
//fungsi fundamental
void LED_SETUP();
void toggle_led(int pin);
// fungsi-fungsi RTOS
/**************************************************************************/
void gate_LED(void* parameters);
void lift(void* paramenters);
/**************************************************************************/
//fungsi ISR
/**************************************************************************/
void IRAM_ATTR handleButtonInterrupt(int btnIndex){
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
toggle_led(pin_arr[btnIndex]);
}
/**************************************************************************/
//WRAPPER ISR
void IRAM_ATTR handleButton1() { handleButtonInterrupt(0); }
void IRAM_ATTR handleButton2() { handleButtonInterrupt(1); }
void IRAM_ATTR handleButton3() { handleButtonInterrupt(2); }
void IRAM_ATTR handleButton4() { handleButtonInterrupt(3); }
void IRAM_ATTR handleButton5() { handleButtonInterrupt(4); }
void setup() {
Serial.begin(9600);
LED_SETUP();
vTaskDelay(1000/portTICK_PERIOD_MS);
Serial.println("\nSelamat datang di lift GACOR!");
}
void loop() {
// put your main code here, to run repeatedly:
}
void LED_SETUP(){
for(int i = 0; i < 5; i++){
pinMode(btn_arr[i], INPUT);
pinMode(pin_arr[i], OUTPUT);
digitalWrite(pin_arr[i], LOW);
}
attachInterrupt(btn_arr[0], handleButton1, RISING);
attachInterrupt(btn_arr[1], handleButton2, RISING);
attachInterrupt(btn_arr[2], handleButton3, RISING);
attachInterrupt(btn_arr[3], handleButton4, RISING);
attachInterrupt(btn_arr[4], handleButton5, RISING);
}
void toggle_led(int pin){
digitalWrite(pin, !digitalRead(pin));
}