Advertisement
Guest User

Arduino IR Control

a guest
Jan 18th, 2017
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.21 KB | None | 0 0
  1. // Include Library's
  2. #include <Wire.h>
  3. #include "LiquidCrystal.h"
  4. #include <IRremote.h>
  5. // Connect via i2c
  6. LiquidCrystal LCD(0);
  7.  
  8.  
  9. const uint16_t BUTTON_CHMI = 0xA25D;
  10. const uint16_t BUTTON_CHAN = 0x629D;
  11. const uint16_t BUTTON_CHPL = 0xE21D;
  12.  
  13. const uint16_t BUTTON_PREV = 0x22DD;
  14. const uint16_t BUTTON_NEXT = 0x02FD;
  15. const uint16_t BUTTON_PLAY = 0xC23D;
  16.  
  17. const uint16_t BUTTON_MINUS = 0xE01F;
  18. const uint16_t BUTTON_PLUS  = 0xA857;
  19. const uint16_t BUTTON_BACK    = 0x906F;
  20.  
  21. const uint16_t BUTTON_0    = 0x6897;
  22. const uint16_t BUTTON_100p = 0x9876;
  23. const uint16_t BUTTON_200p = 0xB04F;
  24.  
  25. const uint16_t BUTTON_1 = 0x30CF;
  26. const uint16_t BUTTON_2 = 0x18E7;
  27. const uint16_t BUTTON_3 = 0x7A85;
  28.  
  29. const uint16_t BUTTON_4 = 0x10EF;
  30. const uint16_t BUTTON_5 = 0x38C7;
  31. const uint16_t BUTTON_6 = 0x5AA5;
  32.  
  33. const uint16_t BUTTON_7 = 0x42BD;
  34. const uint16_t BUTTON_8 = 0x4AB5;
  35. const uint16_t BUTTON_9 = 0x52AD;
  36.  
  37. int back;
  38.  
  39. IRrecv IR(5);
  40.  
  41. decode_results results;
  42. uint16_t lastCode = 0;
  43.  
  44. void setup() {
  45.   Serial.begin(9600);
  46.   LCD.begin(16, 2); //Setup LCD display as 16 by 2
  47.   LCD.setBacklight(HIGH);
  48.  
  49.   IR.enableIRIn();
  50.  
  51.   printAtPosition(4, 0, "ACE Home");
  52.   printAtPosition(5, 1, "System");
  53.   delay(700);
  54.   clearLine(0);
  55.   printAtPosition(5, 0, "Welkom");
  56.   delay(700);
  57.   clearLine(0);
  58. }
  59.  
  60. void loop() {
  61.   if (IR.decode(&results)) {
  62.     uint16_t resultCode = (results.value & 0xFFFF);
  63.     //De remote blijft 0XFFFFFFFF doorsturen als de knop blijft ingedrukt
  64.  
  65.     if (resultCode == 0xFFFF) {
  66.       resultCode = lastCode;
  67.     } else {
  68.       lastCode = resultCode;
  69.     }
  70.  
  71.     switch (resultCode) {
  72.       case BUTTON_CHMI:
  73.         back = 0;
  74.         while(true){
  75.          
  76.           Serial.println("Temperture button pressed:");
  77.           printAtPosition(2, 0, "Temperature: ");
  78.           int x = 20;
  79.           printAtPosition(2, 1, String(x));
  80.           printAtPosition(10, 1, "+/-");
  81.  
  82.           IR.resume();
  83.           Serial.println("Entering IRDECODE if");
  84.           if (IR.decode(&results)) {
  85.             Serial.println("Entered");
  86.             uint16_t resultCode = (results.value & 0xFFFF);
  87.             if (resultCode == 0xFFFF) {
  88.               resultCode = lastCode;
  89.             } else {
  90.               lastCode = resultCode;
  91.             }
  92.             Serial.println("Entering Switch");
  93.             switch (resultCode) {
  94.               case BUTTON_PLUS:
  95.                 Serial.println("Plus pressed");
  96.                 x++;
  97.               case BUTTON_MINUS:
  98.                 Serial.println("Minus pressed");
  99.                 x--;
  100.               case BUTTON_BACK:
  101.                 Serial.println("Back pressed");
  102.                 back = 1;
  103.             }
  104.             if(back==1){break;};
  105.           }
  106.         }
  107.     }
  108.   IR.resume();
  109.   }
  110.   clearLine(0);
  111.  
  112. }
  113.  
  114. void printAtPosition(int x, int y, String text) {
  115.   LCD.setCursor(x, y);
  116.   LCD.print(text);
  117. }
  118. void clearLine(int y) {
  119.   if (y == 1) {
  120.     LCD.setCursor(0, 0);
  121.     LCD.print("                ");
  122.   }
  123.   if (y == 2) {
  124.     LCD.setCursor(0, 1);
  125.     LCD.print("                ");
  126.   }
  127.   if (y == 0) {
  128.     LCD.setCursor(0, 0);
  129.     LCD.print("                ");
  130.     LCD.setCursor(0, 1);
  131.     LCD.print("                ");
  132.   }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement