Advertisement
Guest User

Untitled

a guest
Apr 1st, 2014
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.39 KB | None | 0 0
  1. Dragonkeepers Ardunio IR remote and CPU/RAM monitor for XBMC
  2.  
  3. --code----
  4.  
  5.  
  6. #include <IRremote.h>
  7. #include <LiquidCrystal.h>
  8. LiquidCrystal lcd(0, 1, 2, 3, 4, 5);
  9.  
  10. int RECV_PIN = 12;
  11. int STATUS_PIN = A5;
  12. const unsigned int MAX_INPUT = 8;
  13. IRrecv irrecv(RECV_PIN);
  14.  
  15. decode_results results;
  16.  
  17. void setup()
  18. {
  19. Serial.begin(9600);
  20. irrecv.enableIRIn();
  21. pinMode(STATUS_PIN, OUTPUT);
  22. lcd.begin(16, 2);
  23. lcd.setCursor(0, 0);
  24. lcd.print("X B M C - Remote");
  25.  
  26. }
  27.  
  28. int codeType = -1;
  29. unsigned long codeValue;
  30. unsigned int rawCodes[RAWBUF];
  31. int codeLen;
  32. int toggle = 0;
  33.  
  34. void storeCode(decode_results *results) {
  35. codeValue = results->value;
  36. codeLen = results->bits;
  37. codeType = results->decode_type;
  38. int count = results->rawlen;
  39. if (codeType == UNKNOWN) {
  40. codeLen = results->rawlen - 1;
  41. for (int i = 1; i <= codeLen; i++) {
  42. if (i % 2) {
  43. // Mark
  44. rawCodes[i - 1] = results->rawbuf[i]*USECPERTICK - MARK_EXCESS;
  45. }
  46. else {
  47. // Space
  48. rawCodes[i - 1] = results->rawbuf[i]*USECPERTICK + MARK_EXCESS;
  49. }
  50. }
  51. }
  52. else {
  53. if (codeType == NEC) {
  54. // if (results->value == REPEAT) {
  55. // // Don't record a NEC repeat value as that's useless.
  56. // return;
  57. // }
  58. }
  59. else if (codeType == SONY) {
  60. }
  61. else if (codeType == RC5) {
  62. }
  63. else if (codeType == RC6) {
  64. }
  65. else {
  66. }
  67. Serial.println(results->value, HEX);
  68. if (codeValue == 0x61D610EF) {
  69. // Down
  70. Keyboard.press(0xD9);
  71. Keyboard.release(0xD9);
  72. }
  73. if (codeValue == 0x61D640BF) {
  74. // UP
  75. Keyboard.press(0xDA);
  76. Keyboard.release(0xDA);
  77. }
  78. if (codeValue == 0x61D620DF) {
  79. // Left");
  80. Keyboard.press(0xD8);
  81. Keyboard.release(0xD8);
  82. }
  83. if (codeValue == 0x61D6609F) {
  84. // Right");
  85. Keyboard.press(0xD7);
  86. Keyboard.release(0xD7);
  87. }
  88. if (codeValue == 0x61D6A05F) {
  89. // Select");
  90. Keyboard.press(0xB0);
  91. Keyboard.release(0xB0);
  92. }
  93. if (codeValue == 0x61D630CF) {
  94. //"Vol Up");
  95. Keyboard.press('+');
  96. Keyboard.release('+');
  97. }
  98. if (codeValue == 0x61D618E7) {
  99. // Vol Down");
  100. Keyboard.press('-');
  101. Keyboard.release('-');
  102. }
  103. if (codeValue == 0x61D6708F) {
  104. //Stop");
  105. Keyboard.press('x');
  106. Keyboard.release('x');
  107. }
  108. if (codeValue == 0x61D67887) {
  109. // Play/Pause");
  110. Keyboard.press(' ');
  111. Keyboard.release(' ');
  112. }
  113. if (codeValue == 0x61D648B7) {
  114. //Power");
  115. Keyboard.press('s');
  116. Keyboard.release('s');
  117. }
  118. if (codeValue == 0x61D6C837) {
  119. //Mute");
  120. Keyboard.press(0xC9);
  121. Keyboard.release(0xC9);
  122. }
  123. if (codeValue == 0x61D650AF) {
  124. //Back");
  125. Keyboard.press(0xB2);
  126. Keyboard.release(0xB2);
  127. }
  128. if (codeValue == 0x61D6D827) {
  129. //Subs");
  130. Keyboard.press('t');
  131. Keyboard.release('t');
  132. }
  133. if (codeValue == 0x61D658A7) {
  134. //Display");
  135. Keyboard.press(0xB3);
  136. Keyboard.release(0xB3);
  137. }
  138. if (codeValue == 0x61D6D02F) {
  139. //KeyStart");
  140. Keyboard.begin();
  141. }
  142. if (codeValue == 0x61D6A857) {
  143. //KeyEnd");
  144. Keyboard.end();
  145. }
  146. ///remote2 :
  147. if (codeValue == 0x8061F759) {
  148. //Down");
  149. Keyboard.press(0xD9);
  150. Keyboard.release(0xD9);
  151. }
  152. if (codeValue == 0x80617758) {
  153. //UP");
  154. Keyboard.press(0xDA);
  155. Keyboard.release(0xDA);
  156. }
  157. if (codeValue == 0x8061775A) {
  158. //Left");
  159. Keyboard.press(0xD8);
  160. Keyboard.release(0xD8);
  161. }
  162. if (codeValue == 0x8061775B) {
  163. //Right");
  164. Keyboard.press(0xD7);
  165. Keyboard.release(0xD7);
  166. }
  167. if (codeValue == 0x8061775C) {
  168. //Select");
  169. Keyboard.press(0xB0);
  170. Keyboard.release(0xB0);
  171. }
  172. if (codeValue == 0x8061F710) {
  173. //Vol Up");
  174. Keyboard.press('+');
  175. Keyboard.release('+');
  176. }
  177. if (codeValue == 0x80617711) {
  178. //Vol Down");
  179. Keyboard.press('-');
  180. Keyboard.release('-');
  181. }
  182. if (codeValue == 0x8061772C) {
  183. //Play/Pause");
  184. Keyboard.press(' ');
  185. Keyboard.release(' ');
  186. }
  187. if (codeValue == 0x8061F738) {
  188. //Power");
  189. Keyboard.press('s');
  190. Keyboard.release('s');
  191. }
  192. if (codeValue == 0x8061770D) {
  193. //Mute");
  194. Keyboard.press(0xC9);
  195. Keyboard.release(0xC9);
  196. }
  197. if (codeValue == 0x80617F83) {
  198. //Back");
  199. Keyboard.press(0xB2);
  200. Keyboard.release(0xB2);
  201. }
  202. if (codeValue == 0x80617754) {
  203. //Subs");
  204. Keyboard.press('t');
  205. Keyboard.release('t');
  206. }
  207. if (codeValue == 0x80617771) {
  208. //Display");
  209. Keyboard.press(0xB3);
  210. Keyboard.release(0xB3);
  211. }
  212. }
  213. }
  214. void loop() {
  215. if (irrecv.decode(&results)) {
  216. digitalWrite(STATUS_PIN, HIGH);
  217. storeCode(&results);
  218. irrecv.resume(); // resume receiver
  219. digitalWrite(STATUS_PIN, LOW);
  220. }
  221. String content = "";
  222. char character;
  223.  
  224.  
  225. while(Serial.available()) {
  226. character = Serial.read();
  227. content.concat(character);
  228. }
  229. //------------------------------------------------Edit \/
  230. if (content != "") {
  231.  
  232. if (content == "`") {
  233. content = "";
  234. lcd.setCursor(0,1);
  235. }
  236.  
  237. if (content == "*") {
  238. content = "";
  239. lcd.setCursor(0,0);
  240. }
  241. //-------------------------------------------------------/\
  242. Serial.println(content);
  243. lcd.print(content);
  244. delay(500);
  245. lcd.clear();
  246. }
  247. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement