daily pastebin goal
24%
SHARE
TWEET

GREE remote

a guest Aug 16th, 2013 748 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "IRremote.h"
  2.  
  3. #define GREE_HDR_MARK  9000
  4. #define GREE_HDR_SPACE 4500
  5. #define GREE_BIT_MARK  650
  6. #define GREE_ONE_SPACE 1600
  7. #define GREE_ZERO_SPACE  550
  8.  
  9. // Working modes
  10. #define GREE_MODE_AUTO    0b000    // Automatic
  11. #define GREE_MODE_COOL    0b100    // Cooling
  12. #define GREE_MODE_HIDRO   0b010    // Hidration
  13. #define GREE_MODE_AIR     0b110    // Ventilation
  14. #define GREE_MODE_HEAT    0b001    // Heating
  15. // Fun modes (speed)
  16. #define GREE_FUN_AUTO     0b00
  17. #define GREE_FUN_LOW      0b10
  18. #define GREE_FUN_MEDIUM   0b01
  19. #define GREE_FUN_HIGH     0b11
  20.  
  21. // Temperature
  22. #define GREE_TEMP_16C  0b0000
  23. #define GREE_TEMP_17C  0b1000
  24. #define GREE_TEMP_18C  0b0100
  25. #define GREE_TEMP_19C  0b1100
  26. #define GREE_TEMP_20C  0b0010
  27. #define GREE_TEMP_21C  0b1010
  28. #define GREE_TEMP_22C  0b0110
  29. #define GREE_TEMP_23C  0b1110
  30. #define GREE_TEMP_24C  0b0001
  31. #define GREE_TEMP_25C  0b1001
  32. #define GREE_TEMP_26C  0b0101
  33. #define GREE_TEMP_27C  0b1101
  34. #define GREE_TEMP_28C  0b0011
  35. #define GREE_TEMP_29C  0b1011
  36. #define GREE_TEMP_30C  0b0111
  37. // Misc
  38. #define GREE_ON        1
  39. #define GREE_OFF       0
  40.  
  41.  
  42. struct CondStruct {
  43.    unsigned short align     : 4;    // ---
  44.    unsigned short zeroes    : 6;    // dont know (zeroes)
  45.    unsigned short light     : 1;    // Light (indication) On/Off
  46.    unsigned short turbo     : 1;    // Turbo mode On/Off
  47.    unsigned short timer     : 8;    // Off timer (later)
  48.    unsigned short temp      : 4;    // Temperature to hold
  49.    unsigned short sleep     : 1;    // Sleep (Night) mode On/Off
  50.    unsigned short swing     : 1;    // Swing On/Off
  51.    unsigned short fun       : 2;    // Fun mode (auto/low/med/high)
  52.    unsigned short power     : 1;    // Power On/Off
  53.    unsigned short mode      : 3;    // Working mode (cooling, heating, hidration, etc)
  54. //   unsigned short another   : 7;    // dont know (1010010)
  55. }; // 28 bits + last 7 tail
  56.  
  57. union CondUnion {
  58.   unsigned long data;
  59.   struct CondStruct bitfield;
  60. };
  61.  
  62. IRsend irsend;
  63. union CondUnion data;
  64. int i, diff;
  65. unsigned short temps[15] = {GREE_TEMP_16C,GREE_TEMP_17C,GREE_TEMP_18C,GREE_TEMP_19C,GREE_TEMP_20C,GREE_TEMP_21C,GREE_TEMP_22C,GREE_TEMP_23C,
  66.                           GREE_TEMP_24C,GREE_TEMP_25C,GREE_TEMP_26C,GREE_TEMP_27C,GREE_TEMP_28C,GREE_TEMP_29C,GREE_TEMP_30C};
  67.  
  68. ////////////////////////////////////////////////////////////////////
  69.  
  70. // Based on NEC proto
  71. void sendConditioner(unsigned long data) {
  72.   unsigned char tail = 0b1010010; //7 bits fixed tail
  73.   unsigned char tailmask = 0b01000000; //7 bits
  74.   unsigned long mask = 0x80000000;
  75.  
  76.   irsend.enableIROut(38);
  77.   delay(10);
  78.   irsend.mark(GREE_HDR_MARK);
  79.   irsend.space(GREE_HDR_SPACE);
  80.  
  81.   for (int i = 0; i < 28; i++) {
  82.     if (data & mask) {
  83.       irsend.mark(GREE_BIT_MARK);
  84.       irsend.space(GREE_ONE_SPACE);
  85.     }
  86.     else {
  87.       irsend.mark(GREE_BIT_MARK);
  88.       irsend.space(GREE_ZERO_SPACE);
  89.     }
  90.     mask >>= 1;
  91.   }
  92.  
  93.   for (int i = 0; i < 7; i++) {
  94.     if (tail & tailmask) {
  95.       irsend.mark(GREE_BIT_MARK);
  96.       irsend.space(GREE_ONE_SPACE);
  97.     }
  98.     else {
  99.       irsend.mark(GREE_BIT_MARK);
  100.       irsend.space(GREE_ZERO_SPACE);
  101.     }
  102.     tailmask >>= 1;
  103.   }
  104.  
  105.   irsend.mark(GREE_BIT_MARK);
  106.   irsend.space(0);
  107. }
  108.  
  109. ////////////////////////////////////////////////////////////////////
  110.  
  111. void setup() {
  112.   Serial.begin(9600);
  113.   data.data = 0;
  114.   data.bitfield.mode = GREE_MODE_COOL; // cooling
  115.   data.bitfield.power = GREE_ON;
  116.   data.bitfield.fun = GREE_FUN_MEDIUM;  // medium
  117.   data.bitfield.swing = GREE_OFF;
  118.   data.bitfield.sleep = GREE_OFF;
  119.   data.bitfield.turbo = GREE_OFF;
  120.   data.bitfield.light = GREE_ON;
  121.  
  122.   i = 0; diff = 1;
  123. }
  124.  
  125. ////////////////////////////////////////////////////////////////////
  126.  
  127. void loop() {
  128.   data.bitfield.temp = temps[i];
  129.   sendConditioner(data.data);
  130.   if(i+diff == 15 || i+diff < 0)
  131.     diff *= -1;
  132.    
  133.   i += diff;
  134.   delay(2000);
  135. }
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