I’m a newbie, I would like to dimmer my LED lamp with arduino yun. This is my code. But it doesn’t work.
> #define BLYNK_PRINT Serial
> #include <SPI.h>
> #include <Bridge.h>
> #include <BlynkSimpleYun.h>
> #include <SimpleTimer.h>
> int AC_LOAD = 7; // Output to Opto Triac pin
> int dimming; // Dimming level (0-128) 0 = ON, 128 = OFF
> SimpleTimer timer;
> char auth[] = "xxx";
> void setup()
> {
> Serial.begin(115200);
> Blynk.begin(auth);
> delay(10);
> pinMode(AC_LOAD, OUTPUT);// Set AC Load pin as output
> attachInterrupt(0, zero_crosss_int, RISING); // Choose the zero cross interrupt # from the table above
> }
> BLYNK_WRITE(V1)// slider brillo
> {
> int dim = param.asInt();
> dimming = dim;
> }
> //the interrupt function must take no parameters and return nothing
> void zero_crosss_int() //function to be fired at the zero crossing to dim the light
> {
> // Firing angle calculation : 1 full 50Hz wave =1/50=20ms
> // Every zerocrossing thus: (50Hz)-> 10ms (1/2 Cycle)
> // For 60Hz => 8.33ms (10.000/120)
> // 10ms=10000us
> // (10000us - 10us) / 128 = 75 (Approx) For 60Hz =>65
> int dimtime = (75*dimming); // For 60Hz =>65
> delayMicroseconds(dimtime); // Wait till firing the TRIAC
> digitalWrite(AC_LOAD, HIGH); // Fire the TRIAC
> delayMicroseconds(10); // triac On propogation delay (for 60Hz use 8.33)
> digitalWrite(AC_LOAD, LOW); // No longer trigger the TRIAC (the next zero crossing will swith it off) TRIAC
> }
> void loop() {
> Blynk.run();
> }