Advertisement
anavas

arduino_serial_mpd_temp

Sep 29th, 2012
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.55 KB | None | 0 0
  1. #include <IRremote.h>
  2. #include <LiquidCrystal.h>
  3.  
  4. int RECV_PIN = 8;
  5. IRrecv irrecv(RECV_PIN);
  6. decode_results results;
  7.  
  8. LiquidCrystal lcd (3,2,0,1,4,12,6);
  9.  
  10. int codeType = -1;
  11. unsigned long codeValue;
  12. int codeLen;
  13. int toggle = 0;
  14. int a;
  15. int ai=1;
  16. int b;
  17. int bi=1;
  18. int c;
  19. int ci=1;
  20. float tempC;
  21. int tempPin = 0;
  22.  
  23.  
  24. void setup()
  25. {
  26.   Serial.begin(9600);
  27.   lcd.begin(20,4);
  28.   irrecv.enableIRIn();
  29.   pinMode(5,OUTPUT);
  30.   pinMode(10,OUTPUT);
  31.   pinMode(13,OUTPUT);  
  32. }
  33.  
  34. char getchr()
  35. {
  36.   if (Serial.available()) {
  37.     delay(1);
  38.     while (Serial.available() > 0) {
  39.     char ch = Serial.read();
  40.     return ch;
  41.     }
  42.   }
  43. }
  44.  
  45. void showCode(decode_results *results) {
  46.   codeType = results->decode_type;
  47.   int count = results->rawlen;
  48.   if (codeType == UNKNOWN) {
  49.     codeLen = results->rawlen - 1;
  50.   }
  51.   else{  
  52.     if (codeType == NEC) {
  53.       if (results->value == REPEAT) {
  54.         return;
  55.       }
  56.     }
  57.     else {
  58.     }    
  59.     if (results->value >= 0x800) {
  60.       results->value = results->value - 0x800;
  61.     }    
  62.     Serial.println(results->value, HEX);
  63.     codeValue = results->value;
  64.     codeLen = results->bits;
  65.   }
  66. }
  67.  
  68. void loop()
  69. {
  70.   if(Serial.available() > 0) {
  71.     char in = getchr();
  72.     if(in=='?') {
  73.       lcd.clear();
  74.       lcd.setCursor(0, 0);
  75.     }
  76.     else if(in=='\n') {
  77.     }
  78.     else if(in=='\r') {
  79.     }
  80.     else if(in=='|') {
  81.       lcd.setCursor(0,1);
  82.     }
  83.     else if(in=='<') {
  84.       lcd.setCursor(0,2);
  85.     }
  86.     else if(in=='>') {
  87.       lcd.setCursor(0,3);
  88.     }
  89.     else if(in=='*') {
  90.       if(Serial.available() > 0){
  91.         char in1 = getchr();
  92.         switch (in1)
  93.         {
  94.           case '1':
  95.             a=(ai%2);
  96.             digitalWrite(5,a);
  97.             ai++;
  98.           break;
  99.           case '2':
  100.             b=(bi%2);
  101.             digitalWrite(10,b);
  102.             bi++;
  103.           break;
  104.           case '3':
  105.             c=(ci%2);
  106.             digitalWrite(13,c);
  107.             ci++;
  108.           break;
  109.           case '0':
  110.             tempC = analogRead(tempPin);
  111.             tempC = (5.0 * tempC * 100.0)/1024.0;
  112. [            lcd.clear();
  113.             lcd.setCursor(0, 0);
  114.             lcd.print("CURRENT TEMPERATURE");
  115.             lcd.setCursor(0, 1);
  116.             lcd.print("        ");
  117.             lcd.print((byte)tempC);
  118.             lcd.print(" C   ");
  119.           break;
  120.           default:
  121.           break;
  122.         }
  123.       }
  124.     }
  125.     else
  126.       lcd.print(in);
  127.   }  
  128.  
  129.   if (irrecv.decode(&results)) {
  130.     showCode(&results);
  131.     irrecv.resume();
  132.   }  
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement