Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. unsigned char AC_LOAD = D7;    // Output to Opto Triac pin
  2. unsigned char dimming = 3;  // Dimming level (0-100)
  3. unsigned char i;
  4.  
  5.  
  6. void setup() {
  7.   // put your setup code here, to run once:
  8.   pinMode(AC_LOAD, OUTPUT);// Set AC Load pin as output
  9.   pinMode(D4, INPUT);// Set AC Load pin as output
  10.   attachInterrupt(D4, zero_crosss_int, RISING);
  11.  
  12.   //Serial.begin(9600);
  13.  
  14. }
  15.  
  16. void zero_crosss_int()  // function to be fired at the zero crossing to dim the light
  17. {
  18.   // Firing angle calculation : 1 full 50Hz wave =1/50=20ms
  19.   // Every zerocrossing : (50Hz)-> 10ms (1/2 Cycle) For 60Hz (1/2 Cycle) => 8.33ms
  20.   // 10ms=10000us
  21.  
  22.   int dimtime = (100*dimming);    // For 60Hz =>65    
  23.   delayMicroseconds(dimtime);    // Off cycle
  24.   digitalWrite(AC_LOAD, HIGH);   // triac firing
  25.   delayMicroseconds(10);         // triac On propogation delay (for 60Hz use 8.33)
  26.   digitalWrite(AC_LOAD, LOW);    // triac Off
  27. }
  28.  
  29.  
  30.  
  31. void loop() {
  32.    
  33.        
  34.            
  35.           //Serial.println(pulseIn(8, HIGH));
  36.          
  37.           for (i=5;i<85;i++)
  38.           {
  39.             dimming=i;
  40.             delay(20);
  41.           }
  42.        
  43.           for (i=85;i>5;i--)
  44.           {
  45.             dimming=i;
  46.             delay(20);
  47.           }
  48.                      
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement