Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
658 B
3
Indexable
Never
#include <GyverTimers.h>  
#define USE_SERIAL  Serial
#define D_PIN 16
#define ZERO_CROSS 5

#include <GyverDimmer.h>
Dimmer<D_PIN> dim; 

void setup() {

  USE_SERIAL.begin(9600);
  USE_SERIAL.println("LOAD?");
  attachInterrupt(ZERO_CROSS, isr, RISING); 
  USE_SERIAL.println("LOAD1");
  Timer2.enableISR();
  USE_SERIAL.println("LOAD2");
}

void isr() {
   if (dim.tickZero()) Timer2.setPeriod(dim.getPeriod());
  else Timer2.restart();
}

ISR(TIMER2_A) {
  dim.tickTimer(); 
  Timer2.stop();      
}

void loop() {
  USE_SERIAL.println("LOAD3");
  dim.write(analogRead(A0) / 4);  // принимает 0-255
  delay(100);
  USE_SERIAL.println("LOAD4");
}