Advertisement
AlexShu

IR volume and power of an old stereo system

Jul 17th, 2015
1,562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.53 KB | None | 0 0
  1. /*
  2. This code designed to control the volume and power of an old stereo system via IR with an Arduino
  3. Compiled on Arduino 1.6.4
  4.  
  5. Created with IRecord example of IRemote Library
  6.  
  7. ALEXSHU.COM
  8. */
  9.  
  10. #include <IRremote.h>
  11.  
  12. int RECV_PIN = 10;
  13. int motor_A = 11;
  14. int motor_B = 12;
  15. int power_relay = 13;
  16. long last_vol_time = 0;
  17. long vol_timeout = 100;
  18.  
  19. IRrecv irrecv(RECV_PIN);
  20. IRsend irsend;
  21. decode_results results;
  22.  
  23. void setup()
  24. {
  25.   Serial.begin(9600);
  26.   irrecv.enableIRIn(); // Start the receiver
  27.   pinMode(motor_A, OUTPUT);
  28.   pinMode(motor_B, OUTPUT);
  29.   pinMode(power_relay, OUTPUT);
  30. }
  31.  
  32. // Storage for the recorded code
  33. int codeType = -1; // The type of code
  34. unsigned long codeValue; // The code value if not raw
  35. unsigned int rawCodes[RAWBUF]; // The durations if raw
  36. int codeLen; // The length of the code
  37. int toggle = 0; // The RC5/6 toggle state
  38.  
  39. // Stores the code for later playback
  40. // Most of this code is just logging
  41. void storeCode(decode_results *results) {
  42.   codeType = results->decode_type;
  43.   int count = results->rawlen;
  44.  
  45.    // Serial.println(results->value, DEC);
  46.     codeValue = results->value;
  47.     codeLen = results->bits;
  48.  
  49. }
  50.  
  51. void vol_up(){
  52.   digitalWrite(motor_A ,HIGH);
  53.   digitalWrite(motor_B ,LOW);
  54. }
  55.  
  56. void vol_down(){
  57.   digitalWrite(motor_A ,LOW);
  58.   digitalWrite(motor_B ,HIGH);
  59.  
  60. }
  61.  
  62. void vol_stop(){
  63.   digitalWrite(motor_A ,LOW);
  64.   digitalWrite(motor_B ,LOW);
  65. }
  66.  
  67. void loop() {
  68.  if (irrecv.decode(&results)) {
  69.     storeCode(&results);
  70.  
  71.     if((codeValue == 2148467803) || (codeValue == 2148500571) || (codeValue == 379359532) || (codeValue == 2835546320) || (codeValue == 2964084060)){
  72.       Serial.println("RED | Power");
  73.           digitalWrite(power_relay ,HIGH);
  74.           delay(100);
  75.           digitalWrite(power_relay ,LOW);
  76.           delay(400);
  77.     }
  78.    
  79.     if((codeValue == 2148500572) || (codeValue == 2148467804) || (codeValue == 1064865324) || (codeValue == 1408794736) || (codeValue == 1064865324) || (codeValue == 104438857)){
  80.       Serial.println("Green | Vol -");
  81.       vol_down();
  82.       last_vol_time = millis();
  83.      
  84.     }
  85.    
  86.     if((codeValue == 2148500573) || (codeValue == 2148467805) || (codeValue == 4223161638) || (codeValue == 2384381130) || (codeValue == 2467765715)){
  87.       Serial.println("Yellow | Vol +");
  88.       vol_up();
  89.       last_vol_time = millis();
  90.     }
  91.    
  92.     irrecv.resume(); // resume receiver
  93.  }
  94.  
  95.   // Volwatchdog
  96.   if(millis() - last_vol_time > vol_timeout) {
  97.       vol_stop();
  98.       codeValue = 0;
  99.   }
  100.   codeValue = 0;    
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement