Abdur Rehman Khalil
/
bt
bluetooth link
main.cpp@0:ecf84ddda5e9, 2016-01-02 (annotated)
- Committer:
- ARK4579
- Date:
- Sat Jan 02 11:37:44 2016 +0000
- Revision:
- 0:ecf84ddda5e9
blutooth control
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ARK4579 | 0:ecf84ddda5e9 | 1 | #include "mbed.h" |
ARK4579 | 0:ecf84ddda5e9 | 2 | |
ARK4579 | 0:ecf84ddda5e9 | 3 | //bluetooth module employs Serial Communication. |
ARK4579 | 0:ecf84ddda5e9 | 4 | Serial blutooth(PA_9, PA_10);//Tx, Rx |
ARK4579 | 0:ecf84ddda5e9 | 5 | Serial pc(SERIAL_TX, SERIAL_RX); |
ARK4579 | 0:ecf84ddda5e9 | 6 | |
ARK4579 | 0:ecf84ddda5e9 | 7 | DigitalOut myled(LED1); //LED on your Nucleo Board |
ARK4579 | 0:ecf84ddda5e9 | 8 | DigitalIn btn1(PC_13); //Button on your Nucleo Board |
ARK4579 | 0:ecf84ddda5e9 | 9 | |
ARK4579 | 0:ecf84ddda5e9 | 10 | int main() |
ARK4579 | 0:ecf84ddda5e9 | 11 | { |
ARK4579 | 0:ecf84ddda5e9 | 12 | char t1,t2,h1,h2; |
ARK4579 | 0:ecf84ddda5e9 | 13 | int it1,it2,ih1,ih2; |
ARK4579 | 0:ecf84ddda5e9 | 14 | int it,ih; |
ARK4579 | 0:ecf84ddda5e9 | 15 | //This will print Hello World onto your SmartPhone |
ARK4579 | 0:ecf84ddda5e9 | 16 | blutooth.printf("Hello World !\r\n"); |
ARK4579 | 0:ecf84ddda5e9 | 17 | while(1) { |
ARK4579 | 0:ecf84ddda5e9 | 18 | if(blutooth.readable()) { |
ARK4579 | 0:ecf84ddda5e9 | 19 | if(blutooth.getc()=='t') { |
ARK4579 | 0:ecf84ddda5e9 | 20 | blutooth.printf("Enter temp: "); |
ARK4579 | 0:ecf84ddda5e9 | 21 | while(1) { |
ARK4579 | 0:ecf84ddda5e9 | 22 | if(blutooth.readable()) { |
ARK4579 | 0:ecf84ddda5e9 | 23 | t1=blutooth.getc(); |
ARK4579 | 0:ecf84ddda5e9 | 24 | it1 = t1 - '0'; |
ARK4579 | 0:ecf84ddda5e9 | 25 | break; |
ARK4579 | 0:ecf84ddda5e9 | 26 | } |
ARK4579 | 0:ecf84ddda5e9 | 27 | } |
ARK4579 | 0:ecf84ddda5e9 | 28 | while(1) { |
ARK4579 | 0:ecf84ddda5e9 | 29 | if(blutooth.readable()) { |
ARK4579 | 0:ecf84ddda5e9 | 30 | t2=blutooth.getc(); |
ARK4579 | 0:ecf84ddda5e9 | 31 | it2 = t2 - '0'; |
ARK4579 | 0:ecf84ddda5e9 | 32 | break; |
ARK4579 | 0:ecf84ddda5e9 | 33 | } |
ARK4579 | 0:ecf84ddda5e9 | 34 | } |
ARK4579 | 0:ecf84ddda5e9 | 35 | it = it1*10 + it2; |
ARK4579 | 0:ecf84ddda5e9 | 36 | pc.printf("temp: %d\r\n",it); |
ARK4579 | 0:ecf84ddda5e9 | 37 | } |
ARK4579 | 0:ecf84ddda5e9 | 38 | } |
ARK4579 | 0:ecf84ddda5e9 | 39 | if(blutooth.getc()=='h') { |
ARK4579 | 0:ecf84ddda5e9 | 40 | blutooth.printf("Enter temp: "); |
ARK4579 | 0:ecf84ddda5e9 | 41 | while(1) { |
ARK4579 | 0:ecf84ddda5e9 | 42 | if(blutooth.readable()) { |
ARK4579 | 0:ecf84ddda5e9 | 43 | h1=blutooth.getc(); |
ARK4579 | 0:ecf84ddda5e9 | 44 | ih1 = h1 - '0'; |
ARK4579 | 0:ecf84ddda5e9 | 45 | break; |
ARK4579 | 0:ecf84ddda5e9 | 46 | } |
ARK4579 | 0:ecf84ddda5e9 | 47 | } |
ARK4579 | 0:ecf84ddda5e9 | 48 | while(1) { |
ARK4579 | 0:ecf84ddda5e9 | 49 | if(blutooth.readable()) { |
ARK4579 | 0:ecf84ddda5e9 | 50 | h2=blutooth.getc(); |
ARK4579 | 0:ecf84ddda5e9 | 51 | ih2 = h2 - '0'; |
ARK4579 | 0:ecf84ddda5e9 | 52 | break; |
ARK4579 | 0:ecf84ddda5e9 | 53 | } |
ARK4579 | 0:ecf84ddda5e9 | 54 | } |
ARK4579 | 0:ecf84ddda5e9 | 55 | ih = ih1*10 + ih2; |
ARK4579 | 0:ecf84ddda5e9 | 56 | pc.printf("hum: %d\r\n",ih); |
ARK4579 | 0:ecf84ddda5e9 | 57 | } |
ARK4579 | 0:ecf84ddda5e9 | 58 | } |
ARK4579 | 0:ecf84ddda5e9 | 59 | } |