Skip to content

Instantly share code, notes, and snippets.

@maxpromer
Created May 26, 2017 18:23
Show Gist options
  • Save maxpromer/c9daaeebfc1ec724a062831e5cf1c8d4 to your computer and use it in GitHub Desktop.
Save maxpromer/c9daaeebfc1ec724a062831e5cf1c8d4 to your computer and use it in GitHub Desktop.
#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