Advertisement
ossipee

Rx

Mar 16th, 2015
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.87 KB | None | 0 0
  1. #include <Wire.h> // use Wire library for protocol i2c (A4 = SDA & A5 = SCL)
  2. #include <LiquidCrystal_I2C.h> // use LiquidCrystal_I2C library for control LCD on i2c protocol
  3. #include <VirtualWire.h> // use Virtual library for decode signal from Rx module
  4.  
  5. byte thermometer[8] = //icon for thermometer
  6. {
  7.   B00100,
  8.   B01010,
  9.   B01010,
  10.   B01110,
  11.   B01110,
  12.   B11111,
  13.   B11111,
  14.   B01110
  15. };
  16.  
  17. byte droplet[8] = //icon for droplet
  18. {
  19.   B00100,
  20.   B00100,
  21.   B01010,
  22.   B01010,
  23.   B10001,
  24.   B10001,
  25.   B10001,
  26.   B01110,
  27. };
  28. byte hi[8]=    //icon for heat index
  29. {
  30.   0B00000,
  31.   0B00000,
  32.   0B10101,
  33.   0B01110,
  34.   0B11111,
  35.   0B01110,
  36.   0B10101,
  37.   0B00000,
  38. };                 //(addr, EN,RW,RS,D4,D5,D6,D7,BL,BLpol)
  39. LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); //change the address as per your I2C module
  40. // Sensors
  41. int humidity=0;
  42. int temp=0;
  43. int heat_index=0;
  44. char MsgReceived[21];
  45. int led = 13; //pin for LED
  46.  
  47. void setup()
  48. {
  49.   lcd.begin(20,4); // set up the LCD's number of columns and rows:
  50.   lcd.backlight(); //backlight is now ON
  51.   pinMode(led, OUTPUT);
  52.  
  53.   // VirtualWire
  54.   // Bits per sec
  55.   vw_setup(2000);
  56.   // set pin for connect receiver module
  57.   vw_set_rx_pin(11);  
  58.   // Start the receiver PLL running
  59.   vw_rx_start();      
  60.  
  61.   lcd.begin(20,4);   // initialize the lcd for 20 chars 4 lines, turn on backlight
  62.   lcd.backlight(); // finish with backlight on  
  63.   lcd.createChar(1, thermometer);
  64.   lcd.createChar(2, droplet);
  65.   lcd.createChar(3,hi);
  66.   lcd.clear(); // clear the screen
  67.  
  68. } // END void setup
  69.  
  70. void loop()
  71. {
  72.   uint8_t buf[VW_MAX_MESSAGE_LEN];
  73.   uint8_t buflen = VW_MAX_MESSAGE_LEN;
  74.   //Taking the data from the control base
  75.   if (vw_get_message(buf, &buflen))
  76.   {
  77.     digitalWrite(led, HIGH);
  78.     delay(100);
  79.     int i;
  80.     // Message with a good checksum received, dump it.
  81.     for (i = 0; i < buflen; i++)
  82.     {            
  83.       // Fill Msg Char array with corresponding
  84.       // chars from buffer.  
  85.       MsgReceived[i] = char(buf[i]);
  86.       //Serial.print(MsgReceived[i]);
  87.     }
  88.  
  89.     sscanf(MsgReceived, "%d,%d,%d",&humidity, &temp,&heat_index); // Converts a string to an array
  90.     digitalWrite(led, LOW);
  91.     lcd_display();
  92.     memset( MsgReceived, 0, sizeof(MsgReceived));// This line is for reset the StringReceived
  93.   }
  94. }
  95. void lcd_display()
  96. { lcd.setCursor(1,0);
  97.   lcd.print(" WEATHER STATION ");
  98.   lcd.setCursor(4,1);
  99.   lcd.print("TEMP");
  100.   lcd.setCursor(9, 1);
  101.   lcd.write(1);
  102.   lcd.setCursor(11, 1);
  103.   lcd.print(temp);
  104.   lcd.write(0b11011111);
  105.   lcd.print("C");
  106.   lcd.setCursor(4,2);
  107.   lcd.print("HUM");
  108.   lcd.setCursor(9, 2);
  109.   lcd.write(2);
  110.   lcd.setCursor(11, 2);
  111.   lcd.print(humidity);
  112.   lcd.print("%");
  113.   lcd.setCursor(4,3);
  114.   lcd.print("HI");
  115.   lcd.setCursor(9, 3);
  116.   lcd.write(3);
  117.   lcd.setCursor(11, 3);
  118.   lcd.print(heat_index);
  119.   lcd.write(0b11011111);
  120.   lcd.print("C");
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement