Light Timer using TimeAlarms not working

I was trying to make an alarm timer switch using @bko 's TimeAlarms Library…


    #include "TimeAlarms/TimeAlarms.h"
    
    int flag=0;
    int tripin=D7;
    
    
    void powswtch()
    { 
        if(flag==0)
        {
        digitalWrite(tripin,HIGH);
        flag=1;
        
        }
        else if(flag==1)
        {
        digitalWrite(tripin,LOW);
        flag=0;
        }
    }
    
    
    
    void setup()
    { 
      Time.zone(5.5);
      
      
      pinMode(tripin,OUTPUT); 
     
      // create the alarms 
      Alarm.alarmRepeat(18,46,0, powswtch); 
      Alarm.alarmRepeat(05,45,0, powswtch); 
          
      
    
    }
    
    void  loop()
    { 
    }

But this code doesn’t seem to work for some reason…Alarms are not triggering…

Hi @jiyojolly

You have to call the time alarm delay function periodically so it can test the alarms–it is not interrupt driven.

So change loop to this:

void loop() {
  Alarm.delay(100);
}
2 Likes

ohh…Thanks!!