This works.
I delete one of the dimmers in the sketch.
I changed the values for the dimmer output to test if the time is working oke.
#include <TimeLib.h>
#include <TimeAlarms.h>
//AlarmId id;
int AC_LOAD1 = 10; // Output to Opto Triac pin
volatile int dimming1 = 128; // Dimming level (0-128) 0 = ON, 128 = OFF
void setup() {
// Initialize Serial and wait for port to open:
// Bridge.begin();
Serial.begin(115200);
setTime(8, 29, 45, 1, 1, 11); // set time to Saturday 8:29:30am Jan 1 2011
// create the alarms, to trigger at specific times
Alarm.alarmRepeat(8, 30, 0, LightOn); // 8:30am every day
Alarm.alarmRepeat(8, 30, 15, LightOff); // 8:30;30am every day
Alarm.alarmRepeat(8, 30, 30, LightOn1); // 8:30am every day
Alarm.alarmRepeat(8, 30, 45, LightOff1); // 8:30;30am every day
pinMode(AC_LOAD1, OUTPUT); // Set the AC Load as output
attachInterrupt(0, zero_crosss_int, RISING); // Choose the zero cross interrupt # from the table above
}
void loop() {
Serial.print("min/sec ");
digitalClockDisplay();
Serial.println("dimming values");
Serial.print(dimming1);
//Serial.print(":");
//Serial.println(dimming2);
Alarm.delay(1000); // wait one second between clock display
}
// functions to be called when an alarm triggers:
void LightOn() {
dimming1 = 0; //Full = 0
}
void LightOff() {
dimming1 = 50; //Off = 128
}
void LightOn1() {
dimming1 = 100; //Full = 0
}
void LightOff1() {
dimming1 = 128; //Off = 128
}
void digitalClockDisplay() {
// digital clock display of the time
//Serial.print(hour());
printDigits(minute());
Serial.print(":");
printDigits(second());
Serial.println();
}
void printDigits(int digits) {
//Serial.print(":");
if (digits < 10)
Serial.print('0');
Serial.print(digits);
}
void zero_crosss_int() // function to be fired at the zero crossing to dim the light
{
sei(); //re-enable interrupts
// Firing angle calculation :: 50Hz-> 10ms (1/2 Cycle)
// (10000us - 10us) / 128 = 75 (Approx)
int dimtime1 = (75 * dimming1);
delayMicroseconds(dimtime1);
digitalWrite(AC_LOAD1, HIGH);
delayMicroseconds(10);
digitalWrite(AC_LOAD1, LOW);
}