I know it is quite old topic, but I was trying to achieve similar thing and my search led me here. I wanted to create dynamic alarm to switch color of led strip (ws2812) which can be set remotely from other device (mobile app for example).
I didn't find here the answer I was hoping for, but I found a simple work around. Each alarm has its own ID, which can be simply obtained inside callback. Same ID is returned when alarm is created. What you need to do is to create any structure which bonds this ID to variables you need. I used array of structs because I need to store more values.
// ID stored inside Struct
#include <TimeAlarms.h>
#include <Adafruit_NeoPixel.h>
struct LedTrigger{
int hour;
int minute;
int second;
AlarmId alarmId;
uint32_t color;
};
LedTrigger defaultTrigger = {
.hour = 20,
.minute = 30,
.second = 40,
.alarmId = 0,
.color = led.Color(200,100,0),
};
LedTrigger triggers[40];
int triggerCount = 0;
triggers[triggerCount++] = defaultTrigger;
Then I can create alarm and save its ID
triggers[i].alarmId = Alarm.alarmRepeat(settings.triggers[i].hour, settings.triggers[i].minute, settings.triggers[i].second, ledTrigger);
And inside callback i can obtain ID and use it to ge
void ledTrigger(){
AlarmId id = Alarm.getTriggeredAlarmId();
uint32_t color = getTriggerColor(id);
settings.ledColor = color;
setOneColor(color);
}
void setOneColor(uint32_t color){
settings.ledColor = color;
for (int i = 0; i<LED_COUNT;i++){
led.setPixelColor(i, color);
}
led.show();
}
uint32_t getTriggerColor(AlarmId id){
for (int i = 0; i<settings.triggerCount;i++){
if (settings.triggers[i].alarmId == id) return settings.triggers[i].color;
}
return led.Color(0,0,0);
}