bluetooth link

Dependencies:   mbed

main.cpp

Committer:
ARK4579
Date:
2016-01-02
Revision:
0:ecf84ddda5e9

File content as of revision 0:ecf84ddda5e9:

#include "mbed.h"

//bluetooth module employs Serial Communication.
Serial blutooth(PA_9, PA_10);//Tx, Rx
Serial pc(SERIAL_TX, SERIAL_RX);

DigitalOut myled(LED1); //LED on your Nucleo Board
DigitalIn btn1(PC_13);  //Button on your Nucleo Board

int main()
{
    char t1,t2,h1,h2;
    int it1,it2,ih1,ih2;
    int it,ih;
    //This will print Hello World onto your SmartPhone
    blutooth.printf("Hello World !\r\n");
    while(1) {
        if(blutooth.readable()) {
            if(blutooth.getc()=='t') {
                blutooth.printf("Enter temp: ");
                while(1) {
                    if(blutooth.readable()) {
                        t1=blutooth.getc();
                        it1 = t1 - '0';
                        break;
                    }
                }
                while(1) {
                    if(blutooth.readable()) {
                        t2=blutooth.getc();
                        it2 = t2 - '0';
                        break;
                    }
                }
                it = it1*10 + it2;
                pc.printf("temp: %d\r\n",it);
            }
        }
        if(blutooth.getc()=='h') {
            blutooth.printf("Enter temp: ");
            while(1) {
                if(blutooth.readable()) {
                    h1=blutooth.getc();
                    ih1 = h1 - '0';
                    break;
                }
            }
            while(1) {
                if(blutooth.readable()) {
                    h2=blutooth.getc();
                    ih2 = h2 - '0';
                    break;
                }
            }
            ih = ih1*10 + ih2;
            pc.printf("hum: %d\r\n",ih);
        }
    }
}