If i use the code below nothing is happening.
The timealarm code works fine but if i insert the dimmer code it doesn't work any more.
I think i make a mistake with logical order.
#include <Console.h>
#include <TimeLib.h>
#include <TimeAlarms.h>
AlarmId id;
int AC_LOAD1 = 10; // Output to Opto Triac pin
int AC_LOAD2 = 11; // Output to Opto Triac pin
int dimming1 = 128; // Dimming level (0-128) 0 = ON, 128 = OFF
int dimming2 = 128; // Dimming level (0-128) 0 = ON, 128 = OFF
void setup() {
// Initialize Console and wait for port to open:
Bridge.begin();
Console.begin();
setTime(8,29,0,1,1,11); // set time to Saturday 8:29:00am Jan 1 2011
// create the alarms, to trigger at specific times
Alarm.alarmRepeat(8,30,0, LightOn); // 8:30am every day
Alarm.alarmRepeat(8,35,0, LightOff); // 8:35am every day
pinMode(AC_LOAD1, OUTPUT); // Set the AC Load as output
pinMode(AC_LOAD2, OUTPUT); // Set the AC Load as output
attachInterrupt(0, zero_crosss_int, RISING); // Choose the zero cross interrupt # from the table above
}
void loop() {
digitalClockDisplay();
Alarm.delay(100); // wait one second between clock display
}
// functions to be called when an alarm triggers:
void LightOn() {
dimming1 = 0; //Full = 0
dimming2 = 0; //Full = 0
}
void LightOff() {
dimming1 = 128; //Off = 128
dimming2 = 128; //Off = 128
}
void digitalClockDisplay() {
// digital clock display of the time
//Console.print(hour());
printDigits(minute());
printDigits(second());
//Console.println();
}
void printDigits(int digits) {
//Console.print(":");
if (digits < 10)
Console.print('0');
//Console.print(digits);
}
void zero_crosss_int() // function to be fired at the zero crossing to dim the light
{
// Firing angle calculation :: 50Hz-> 10ms (1/2 Cycle)
// (10000us - 10us) / 128 = 75 (Approx)
int dimtime1 = (75*dimming1);
int dimtime2 = (75*dimming2);
if ( dimtime1 > dimtime2)
{ delayMicroseconds(dimtime2);
digitalWrite(AC_LOAD2, HIGH);
delayMicroseconds(10);
digitalWrite(AC_LOAD2, LOW);
delayMicroseconds( dimtime1 - dimtime2);
digitalWrite(AC_LOAD1, HIGH);
delayMicroseconds(10);
digitalWrite(AC_LOAD1, LOW);
}
else
{ delayMicroseconds(dimtime1);
digitalWrite(AC_LOAD1, HIGH);
delayMicroseconds(10);
digitalWrite(AC_LOAD1, LOW);
delayMicroseconds( dimtime2 - dimtime1);
digitalWrite(AC_LOAD2, HIGH);
delayMicroseconds(10);
digitalWrite(AC_LOAD2, LOW);
}