Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

LGACSendDemo.ino 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. #include <IRremote.h>
  2. #include <Wire.h>
  3. IRsend irsend;
  4. // not used
  5. int RECV_PIN = 11;
  6. IRrecv irrecv (RECV_PIN);
  7. const int AC_TYPE = 0;
  8. // 0 : TOWER
  9. // 1 : WALL
  10. //
  11. int AC_HEAT = 0;
  12. // 0 : cooling
  13. // 1 : heating
  14. int AC_POWER_ON = 0;
  15. // 0 : off
  16. // 1 : on
  17. int AC_AIR_ACLEAN = 0;
  18. // 0 : off
  19. // 1 : on --> power on
  20. int AC_TEMPERATURE = 27;
  21. // temperature : 18 ~ 30
  22. int AC_FLOW = 1;
  23. // 0 : low
  24. // 1 : mid
  25. // 2 : high
  26. // if AC_TYPE =1, 3 : change
  27. //
  28. const int AC_FLOW_TOWER[3] = {0, 4, 6};
  29. const int AC_FLOW_WALL[4] = {0, 2, 4, 5};
  30. unsigned long AC_CODE_TO_SEND;
  31. int r = LOW;
  32. int o_r = LOW;
  33. byte a, b;
  34. void ac_send_code(unsigned long code)
  35. {
  36. Serial.print("code to send : ");
  37. Serial.print(code, BIN);
  38. Serial.print(" : ");
  39. Serial.println(code, HEX);
  40. irsend.sendLG(code, 28);
  41. }
  42. void ac_activate(int temperature, int air_flow)
  43. {
  44. int AC_MSBITS1 = 8;
  45. int AC_MSBITS2 = 8;
  46. int AC_MSBITS3 = 0;
  47. int AC_MSBITS4 ;
  48. if ( AC_HEAT == 1 ) {
  49. // heating
  50. AC_MSBITS4 = 4;
  51. } else {
  52. // cooling
  53. AC_MSBITS4 = 0;
  54. }
  55. int AC_MSBITS5 = temperature - 15;
  56. int AC_MSBITS6 ;
  57. if ( AC_TYPE == 0) {
  58. AC_MSBITS6 = AC_FLOW_TOWER[air_flow];
  59. } else {
  60. AC_MSBITS6 = AC_FLOW_WALL[air_flow];
  61. }
  62. int AC_MSBITS7 = (AC_MSBITS3 + AC_MSBITS4 + AC_MSBITS5 + AC_MSBITS6) & B00001111;
  63. AC_CODE_TO_SEND = AC_MSBITS1 << 4 ;
  64. AC_CODE_TO_SEND = (AC_CODE_TO_SEND + AC_MSBITS2) << 4;
  65. AC_CODE_TO_SEND = (AC_CODE_TO_SEND + AC_MSBITS3) << 4;
  66. AC_CODE_TO_SEND = (AC_CODE_TO_SEND + AC_MSBITS4) << 4;
  67. AC_CODE_TO_SEND = (AC_CODE_TO_SEND + AC_MSBITS5) << 4;
  68. AC_CODE_TO_SEND = (AC_CODE_TO_SEND + AC_MSBITS6) << 4;
  69. AC_CODE_TO_SEND = (AC_CODE_TO_SEND + AC_MSBITS7);
  70. ac_send_code(AC_CODE_TO_SEND);
  71. AC_POWER_ON = 1;
  72. AC_TEMPERATURE = temperature;
  73. AC_FLOW = air_flow;
  74. }
  75. void ac_change_air_swing(int air_swing)
  76. {
  77. if ( AC_TYPE == 0) {
  78. if ( air_swing == 1) {
  79. AC_CODE_TO_SEND = 0x881316B;
  80. } else {
  81. AC_CODE_TO_SEND = 0x881317C;
  82. }
  83. } else {
  84. if ( air_swing == 1) {
  85. AC_CODE_TO_SEND = 0x8813149;
  86. } else {
  87. AC_CODE_TO_SEND = 0x881315A;
  88. }
  89. }
  90. ac_send_code(AC_CODE_TO_SEND);
  91. }
  92. void ac_power_down()
  93. {
  94. AC_CODE_TO_SEND = 0x88C0051;
  95. ac_send_code(AC_CODE_TO_SEND);
  96. AC_POWER_ON = 0;
  97. }
  98. void ac_air_clean(int air_clean)
  99. {
  100. if ( air_clean == 1) {
  101. AC_CODE_TO_SEND = 0x88C000C;
  102. } else {
  103. AC_CODE_TO_SEND = 0x88C0084;
  104. }
  105. ac_send_code(AC_CODE_TO_SEND);
  106. AC_AIR_ACLEAN = air_clean;
  107. }
  108. void setup()
  109. {
  110. Serial.begin(38400);
  111. delay(1000);
  112. Wire.begin(7);
  113. Wire.onReceive(receiveEvent);
  114. Serial.println(" - - - T E S T - - - ");
  115. /* test
  116. ac_activate(25, 1);
  117. delay(5000);
  118. ac_activate(27, 2);
  119. delay(5000);
  120. */
  121. }
  122. void loop()
  123. {
  124. ac_activate(25, 1);
  125. delay(5000);
  126. ac_activate(27, 0);
  127. delay(5000);
  128. if ( r != o_r) {
  129. /*
  130. # a : mode or temp b : air_flow, temp, swing, clean, cooling/heating
  131. # 18 ~ 30 : temp 0 ~ 2 : flow // on
  132. # 0 : off 0
  133. # 1 : on 0
  134. # 2 : air_swing 0 or 1
  135. # 3 : air_clean 0 or 1
  136. # 4 : air_flow 0 ~ 2 : flow
  137. # 5 : temp 18 ~ 30
  138. # + : temp + 1
  139. # - : temp - 1
  140. # m : change cooling to air clean, air clean to cooling
  141. */
  142. Serial.print("a : ");
  143. Serial.print(a);
  144. Serial.print(" b : ");
  145. Serial.println(b);
  146. switch (a) {
  147. case 0: // off
  148. ac_power_down();
  149. break;
  150. case 1: // on
  151. ac_activate(AC_TEMPERATURE, AC_FLOW);
  152. break;
  153. case 2:
  154. if ( b == 0 || b == 1 ) {
  155. ac_change_air_swing(b);
  156. }
  157. break;
  158. case 3: // 1 : clean on, power on
  159. if ( b == 0 || b == 1 ) {
  160. ac_air_clean(b);
  161. }
  162. break;
  163. case 4:
  164. if ( 0 <= b && b <= 2 ) {
  165. ac_activate(AC_TEMPERATURE, b);
  166. }
  167. break;
  168. case 5:
  169. if (18 <= b && b <= 30 ) {
  170. ac_activate(b, AC_FLOW);
  171. }
  172. break;
  173. case '+':
  174. if ( 18 <= AC_TEMPERATURE && AC_TEMPERATURE <= 29 ) {
  175. ac_activate((AC_TEMPERATURE + 1), AC_FLOW);
  176. }
  177. break;
  178. case '-':
  179. if ( 19 <= AC_TEMPERATURE && AC_TEMPERATURE <= 30 ) {
  180. ac_activate((AC_TEMPERATURE - 1), AC_FLOW);
  181. }
  182. break;
  183. case 'm':
  184. /*
  185. if ac is on, 1) turn off, 2) turn on ac_air_clean(1)
  186. if ac is off, 1) turn on, 2) turn off ac_air_clean(0)
  187. */
  188. if ( AC_POWER_ON == 1 ) {
  189. ac_power_down();
  190. delay(100);
  191. ac_air_clean(1);
  192. } else {
  193. if ( AC_AIR_ACLEAN == 1) {
  194. ac_air_clean(0);
  195. delay(100);
  196. }
  197. ac_activate(AC_TEMPERATURE, AC_FLOW);
  198. }
  199. break;
  200. default:
  201. if ( 18 <= a && a <= 30 ) {
  202. if ( 0 <= b && b <= 2 ) {
  203. ac_activate(a, b);
  204. }
  205. }
  206. }
  207. o_r = r ;
  208. }
  209. delay(100);
  210. }
  211. void receiveEvent(int howMany)
  212. {
  213. a = Wire.read();
  214. b = Wire.read();
  215. r = !r ;
  216. }