#define pinLed_Merah 19
#define pinLed_Kuning 18
#define pinPB1 34
unsigned char StatusPB1, Counter;
unsigned long PrevMillis, Interval=100;
TaskHandle_t Info;
void SerialMonitor( void * parameter) {
for(;;) {
Serial.print("for() running on core ");
Serial.println(xPortGetCoreID());
vTaskDelay(1000 / portTICK_PERIOD_MS); // 1 detk
}
}
void TombolPB1(){
portDISABLE_INTERRUPTS();
Counter++;
Serial.print("Count= ");
Serial.println(Counter);
StatusPB1 =digitalRead(pinPB1);
while(StatusPB1 == LOW){
Serial.print("status pb1 = ");
Serial.println(StatusPB1);
StatusPB1 =digitalRead(pinPB1);
vTaskDelay(500 / portTICK_PERIOD_MS);
digitalWrite(pinLed_Kuning,digitalRead(!pinLed_Kuning));
}
// Re-enable interrupts
portENABLE_INTERRUPTS();
}
void setup() {
Serial.begin(115200);
Serial.print("setup() running on core ");
Serial.println(xPortGetCoreID());
pinMode(pinLed_Merah, OUTPUT);
pinMode(pinLed_Kuning, OUTPUT);
pinMode(pinPB1, INPUT_PULLUP);
//-----------------------------------------------
xTaskCreatePinnedToCore(
SerialMonitor, /* Function to implement the task */
"Task1", /* Name of the task */
1000, /* Stack size in words */
NULL, /* Task input parameter */
1, /* Priority of the task */
&Info, /* Task handle. */
0); /* Core where the task should run */
//------------------------------------------------------------
attachInterrupt(digitalPinToInterrupt(pinPB1), TombolPB1, FALLING);
}
void loop() {
digitalWrite(pinLed_Merah, HIGH); // LED OFF
vTaskDelay(1000 / portTICK_PERIOD_MS); // 1000 mS
digitalWrite(pinLed_Merah, LOW); // Led ON
vTaskDelay(1000 / portTICK_PERIOD_MS);
}