Created
May 26, 2017 18:23
-
-
Save maxpromer/c9daaeebfc1ec724a062831e5cf1c8d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define PWM_PIN 23 | |
#define Z_C_PIN 22 | |
int DimmerValue = 100; | |
hw_timer_t *timer = NULL; | |
void DimmerSetup() { | |
pinMode(PWM_PIN, OUTPUT); | |
pinMode(Z_C_PIN, INPUT); | |
attachInterrupt(Z_C_PIN, [](){ | |
if (DimmerValue > 5) { | |
timerAlarmWrite(timer, DimmerValue * 100, true); | |
timerAlarmEnable(timer); | |
timerStart(timer); | |
} else { | |
digitalWrite(PWM_PIN, HIGH); | |
} | |
}, RISING); | |
timer = timerBegin(3, 80, true); | |
timerAttachInterrupt(timer, [](){ | |
digitalWrite(PWM_PIN, HIGH); | |
delayMicroseconds(10); | |
digitalWrite(PWM_PIN, LOW); | |
timerStop(timer); | |
}, true); | |
} | |
void setup() { | |
DimmerSetup(); | |
} | |
void loop() { | |
DimmerValue = (DimmerValue == 0) ? 100 : DimmerValue - 1; | |
delay(10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment