/*
  程序: FREERTOS - 结构体多参数传递
  作业: 添加LED3
  公众号:孤独的二进制
*/

typedef struct {
  byte pin;
  int delayTime;
} LEDFLASH;

/*
void ledFlash(void *pt) {
  LEDFLASH * ptLedFlash = (LEDFLASH *)pt;
  LEDFLASH led = *ptLedFlash;

  pinMode(led.pin,OUTPUT);
  while (1) {
    digitalWrite(led.pin, !digitalRead(led.pin));
    vTaskDelay(led.delayTime);
  }
}
*/

void ledFlash(void *pt) {
  LEDFLASH * ptLedFlash = (LEDFLASH *)pt;
  byte pin = ptLedFlash->pin;
  int delayTime = ptLedFlash->delayTime;

  pinMode(pin,OUTPUT);
  while (1) {
    digitalWrite(pin, !digitalRead(pin));
    vTaskDelay(delayTime);
  }
}
 
LEDFLASH led1, led2;

void setup() {
  Serial.begin(9600);

 
  led1.pin = 23;
  led1.delayTime = 1000;
  led2.pin = 21;
  led2.delayTime = 3000;


if (xTaskCreate(ledFlash,
                  "FLASH LED",
                  1024,
                  (void *)&led1,
                  1,
                  NULL) == pdPASS)
    Serial.println("led1 flash task Created.");

if (xTaskCreate(ledFlash,
                  "FLASH LED",
                  1024,
                  (void *)&led2,
                  1,
                  NULL) == pdPASS)
    Serial.println("led2 flash task Created.");

}

void loop() {
}