Skip to content

Can't use two timer in code #420

@maxpromer

Description

@maxpromer

Hello !, I use NodeMCU-32S board. I can't use 2 timer in code, the second timer not callback via timerAlarmWrite() but the first timer can callback and work.
My code :

#define LED1 LED_BUILTIN
#define LED2 23

hw_timer_t *timerOne = NULL;
hw_timer_t *timerTwo = NULL;

void onTimerOne(){
  digitalWrite(LED1, !digitalRead(LED1));
}

void onTimerTwo(){
  digitalWrite(LED2, !digitalRead(LED2));
}

void setup() {
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  
  timerOne = timerBegin(0, 80, true);
  timerAttachInterrupt(timerOne, &onTimerOne, true);
  timerAlarmWrite(timerOne, 500000, true);
  timerAlarmEnable(timerOne);
  timerStart(timerOne);

  timerTwo = timerBegin(1, 80, true);
  timerAttachInterrupt(timerTwo, &onTimerTwo, true);
  timerAlarmWrite(timerTwo, 300000, true);
  timerAlarmEnable(timerTwo);
  timerStart(timerTwo);
}

void loop() {}

LED on board blink but LED on GPIO23 not blink.

Thank for reply.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions