Advertisement
babyyoda_

Interrupt2

Feb 15th, 2021
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <IRremote.h>
  3. #define triacPulse A0
  4. #define ZCD 2           // Zero Cross Detector
  5. #define RECV_PIN 7      // IR Pin
  6.  
  7. IRrecv irrecv(RECV_PIN);
  8. decode_results results;
  9. unsigned long key_value = 0;
  10. const byte ZCDinterruptPin = 2;
  11. int x=0;
  12. bool speed1 = false;
  13. bool speed2 = false;
  14. bool speed3 = false;
  15.  
  16. void setup() {
  17.   Serial.begin(9600);
  18.   irrecv.enableIRIn();
  19.   irrecv.blink13(true);
  20.   pinMode(ZCD, INPUT_PULLUP);
  21.   pinMode(triacPulse, OUTPUT);
  22.   //  attachInterrupt(digitalPinToInterrupt(ZCDinterruptPin), acon, FALLING); // attach Interrupt at PIN2
  23. }
  24.  
  25. void loop() {
  26.  
  27.   if (irrecv.decode(&results)) {
  28.     if (results.value == 0XFFFFFFFF)
  29.       results.value = key_value;
  30.  
  31.     if ((results.value == 0x88C0051)) {                                     // Button 1
  32.       // TODO
  33.     }
  34.  
  35.     if ((results.value == 0x88C000C)) {                                     // Button 2 -Speed1
  36.       speed1 = true;
  37.       speed2 = false;
  38.       speed3 = false;
  39.     }
  40.     if ((results.value == 0x8810089)) {                                     // Button 3 -Speed2
  41.       speed1 = false;
  42.       speed2 = true;
  43.       speed3 = false;
  44.     }
  45.     if ((results.value == 0x8808350)) {                                     // Button 4 -Speed3
  46.       speed1 = false;
  47.       speed2 = false;
  48.       speed3 = true;
  49.     }
  50.     key_value = results.value;
  51.     irrecv.resume();
  52.   }
  53.  
  54.   if (speed1 == true && speed2 == false && speed3 == false) { // speed 1
  55.     x = 6600;
  56.     attachInterrupt(digitalPinToInterrupt(ZCDinterruptPin), acon, FALLING); // attach Interrupt at PIN2
  57.   }
  58.   if (speed1 == false && speed2 == true && speed3 == false) { // speed 2
  59.     x = 4800;
  60.     attachInterrupt(digitalPinToInterrupt(ZCDinterruptPin), acon, FALLING); // attach Interrupt at PIN2
  61.   }
  62.   if (speed1 == false && speed2 == false && speed3 == true) { // speed 3
  63.     x = 2500;
  64.     attachInterrupt(digitalPinToInterrupt(ZCDinterruptPin), acon, FALLING); // attach Interrupt at PIN2
  65.   }
  66. }
  67.  
  68.  
  69.  
  70. void acon()
  71. {
  72.     detachInterrupt(digitalPinToInterrupt(ZCDinterruptPin));
  73.     delayMicroseconds(x); //
  74.     digitalWrite(triacPulse, HIGH);
  75.     delayMicroseconds(50);  //delay 50 uSec on output pulse to turn on triac
  76.     digitalWrite(triacPulse, LOW);
  77. }
  78.  
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement