Advertisement
Guest User

Untitled

a guest
Jun 19th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. unsigned char AC_LOAD = 7; // 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. attachInterrupt(1, zero_crosss_int, RISING);
  10.  
  11. // Serial.begin(9600);
  12.  
  13. }
  14.  
  15. void zero_crosss_int() // function to be fired at the zero crossing to dim the light
  16. {
  17. // Firing angle calculation : 1 full 50Hz wave =1/50=20ms
  18. // Every zerocrossing : (50Hz)-> 10ms (1/2 Cycle) For 60Hz (1/2 Cycle) => 8.33ms
  19. // 10ms=10000us
  20.  
  21. int dimtime = (100*dimming); // For 60Hz =>65
  22. delayMicroseconds(dimtime); // Off cycle
  23. digitalWrite(AC_LOAD, HIGH); // triac firing
  24. delayMicroseconds(10); // triac On propogation delay (for 60Hz use 8.33)
  25. digitalWrite(AC_LOAD, LOW); // triac Off
  26. }
  27.  
  28.  
  29.  
  30. void loop() {
  31.  
  32.  
  33.  
  34. // Serial.println(pulseIn(8, HIGH));
  35.  
  36. for (i=5;i<85;i++)
  37. {
  38. dimming=i;
  39. delay(20);
  40. }
  41.  
  42. for (i=85;i>5;i--)
  43. {
  44. dimming=i;
  45. delay(20);
  46. }
  47.  
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement