SHARE
TWEET

Untitled

a guest Oct 21st, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include "IRremote.h"
  3.  
  4. int receiver = 11; // Signal Pin of IR receiver to Arduino Digital Pin 11
  5.  
  6. /*-----( Declare objects )-----*/
  7. IRrecv irrecv(receiver);     // create instance of 'irrecv'
  8. decode_results results;      // create instance of 'decode_results'
  9.  
  10. #define ENABLE 5
  11. #define DIRA 3
  12. #define DIRB 4
  13.  int num=0;
  14.  int onState = 1;
  15.  
  16. /*-----( Function )-----*/
  17. void translateIR() // takes action based on IR code received
  18.  
  19. // describing Remote IR codes
  20.  
  21. {
  22.  
  23.   switch(results.value)
  24.  
  25.   {
  26.   case 0xFFA25D: Serial.println("POWER"); onState=-onState; break;
  27.   case 0xFFE21D: Serial.println("FUNC/STOP"); break;
  28.   case 0xFF629D: Serial.println("VOL+"); break;
  29.   case 0xFF22DD: Serial.println("FAST BACK");    break;
  30.   case 0xFF02FD: Serial.println("PAUSE");    break;
  31.   case 0xFFC23D: Serial.println("FAST FORWARD");   break;
  32.   case 0xFFE01F: Serial.println("DOWN");    break;
  33.   case 0xFFA857: Serial.println("VOL-");    break;
  34.   case 0xFF906F: Serial.println("UP");    break;
  35.   case 0xFF9867: Serial.println("EQ");    break;
  36.   case 0xFFB04F: Serial.println("ST/REPT");    break;
  37.   case 0xFF6897: Serial.println("0"); num=0;    break;
  38.   case 0xFF30CF: Serial.println("1"); num=1;   break;
  39.   case 0xFF18E7: Serial.println("2");  num=2;  break;
  40.   case 0xFF7A85: Serial.println("3"); num=3;   break;
  41.   case 0xFF10EF: Serial.println("4"); num=4;   break;
  42.   case 0xFF38C7: Serial.println("5"); num=5;   break;
  43.   case 0xFF5AA5: Serial.println("6"); num=6;   break;
  44.   case 0xFF42BD: Serial.println("7");  num=7;  break;
  45.   case 0xFF4AB5: Serial.println("8");  num=8;  break;
  46.   case 0xFF52AD: Serial.println("9"); num=9;   break;
  47.   case 0xFFFFFFFF: Serial.println(" REPEAT");break;  
  48.  
  49.   default:
  50.     Serial.println(" other button   ");
  51.  
  52.   }// End Case
  53.  
  54.   delay(500); // Do not get immediate repeat
  55.  
  56.  
  57. } //END translateIR
  58.  
  59.  
  60. void setup() {
  61.   //---set pin direction
  62.   pinMode(ENABLE,OUTPUT);
  63.   pinMode(DIRA,OUTPUT);
  64.   pinMode(DIRB,OUTPUT);
  65.  
  66.   Serial.println("IR Receiver Button Decode");
  67.   irrecv.enableIRIn(); // Start the receiver
  68. }
  69.  
  70. void loop() {
  71.   //---back and forth example
  72.    if (irrecv.decode(&results)) // have we received an IR signal?
  73.  
  74.   {
  75.     translateIR();
  76.     irrecv.resume(); // receive the next value
  77.   }  
  78.     if (onState==true)
  79.     {
  80.     digitalWrite(ENABLE,HIGH); // enable on
  81.     digitalWrite(DIRA,((255.0/9.0)*num)+1);
  82.    
  83.     }
  84.     else
  85.     {
  86.       digitalWrite(ENABLE,LOW); // enable on
  87.     digitalWrite(DIRA,0);
  88.     }
  89.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top