master for temp/humid k64f

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Master_Main_Temp.cpp Source File

Master_Main_Temp.cpp

00001 #include "mbed.h"
00002 Timeout response;
00003 
00004 DigitalOut LED3a(D4);
00005 DigitalOut LED2a(D5);
00006 DigitalOut green(LED_GREEN);
00007 DigitalOut red(LED_RED);
00008 DigitalIn  sw2(SW2);
00009 Serial pc(USBTX, USBRX );
00010 Serial blue(PTC15, PTC14); //tx, rx
00011 
00012 
00013 
00014 int main()
00015 {
00016     char hold = 'b';
00017     char send = 'Z';
00018     pc.baud(9600);
00019     blue.baud(9600);
00020     printf("Master connecting to the slave\n");
00021     int flagt = 0; 
00022       int farenh; 
00023       int dew;
00024     
00025     while (true) {
00026        blue.putc(send);
00027         wait(0.5f); // wait a small period of time       
00028       //  printf("\n waiting \n\r");
00029         if(blue.readable())//Determine if there is a character available to read.
00030         {
00031               
00032                //--------------------------Temperature Module-----------------------------
00033               //  printf("\n entering \n\r");
00034                  
00035                 hold = blue.getc();
00036                 farenh = hold - '0';
00037                 
00038                 wait(0.5f);
00039                 
00040                 hold = blue.getc();
00041                 dew = hold - '0';
00042 
00043                 
00044                 //--------------------------Temperature Module End----------------------------
00045         
00046                 //-----------------------------------------------------------------------------
00047                 
00048                printf("\nTemperature = %iF \n\rDewpoint = %i\n\r", farenh, dew);
00049             
00050         }
00051         
00052 
00053         wait(0.5f); // wait a small period of time        
00054         green = !green; // toggle a led
00055                 if(farenh <= 70) {
00056                     flagt = -1; 
00057                     printf("Home Heat Triggered. \n\r"); 
00058                 }
00059                 if (farenh >= 77){
00060                     printf("Home Cooling Triggered. \n\r"); 
00061                     flagt = 1;    
00062                 }
00063                 else {     
00064                 flagt = 0;
00065                 }
00066         
00067         if(flagt == 1)
00068         {
00069             for(int count = 0; count < 2; count++)
00070             {
00071                 wait(0.5f);
00072                 LED3a = !LED3a;
00073             } 
00074         }
00075          else if(flagt == -1)
00076         {
00077             for(int count = 0; count < 2; count++)
00078             {
00079                 wait(0.5f);
00080                 LED2a = !LED2a;
00081             } 
00082         }
00083     }
00084 
00085 }