LED Cortrol HC-05 Bluetooth LCP1768. Type R G B in terminal to turn on led R G B

Dependencies:   mbed

Fork of Serial_To_Bluetooth_Helloworld_WIZwiki-W7500 by WIZnet

Committer:
Tuxitheone
Date:
Fri Jul 08 09:36:57 2016 +0000
Revision:
1:eec2c6c7d58b
Parent:
0:22832bff21a1
HC-05 Bluetooth LCP1768

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joon874 0:22832bff21a1 1 #include "mbed.h"
joon874 0:22832bff21a1 2
joon874 0:22832bff21a1 3 /* Digital Out Pin Configuration */
Tuxitheone 1:eec2c6c7d58b 4 DigitalOut RED(p21);
Tuxitheone 1:eec2c6c7d58b 5 DigitalOut GREEN(p22);
Tuxitheone 1:eec2c6c7d58b 6 DigitalOut BLUE(p23);
joon874 0:22832bff21a1 7
joon874 0:22832bff21a1 8 /* UART Pin Configuration */
Tuxitheone 1:eec2c6c7d58b 9
Tuxitheone 1:eec2c6c7d58b 10 RawSerial pc(USBTX, USBRX);//Serial LOG
Tuxitheone 1:eec2c6c7d58b 11 Serial bt(p9, p10); // tx, rx to Bluetooth
joon874 0:22832bff21a1 12
joon874 0:22832bff21a1 13
joon874 0:22832bff21a1 14 int main(void)
joon874 0:22832bff21a1 15 {
joon874 0:22832bff21a1 16 /* baudrate configuration */
Tuxitheone 1:eec2c6c7d58b 17 pc.baud(9600);
joon874 0:22832bff21a1 18 bt.baud(9600);
joon874 0:22832bff21a1 19
Tuxitheone 1:eec2c6c7d58b 20 pc.printf("Bluetooth RGB LED terminal\n\r"); //pc.printf("WIZwiki-W7500 BT\n\r");
Tuxitheone 1:eec2c6c7d58b 21 bt.printf("Bluetooth RGB LED terminal\n\r"); //pc.printf("WIZwiki-W7500 BT\n\r");
joon874 0:22832bff21a1 22
joon874 0:22832bff21a1 23 char ch;
joon874 0:22832bff21a1 24 char msg[256];
joon874 0:22832bff21a1 25
joon874 0:22832bff21a1 26 while(1)
joon874 0:22832bff21a1 27 {
joon874 0:22832bff21a1 28 /* WIZwiki-W7500 to Bluetooth */
joon874 0:22832bff21a1 29 if(pc.readable())
joon874 0:22832bff21a1 30 {
Tuxitheone 1:eec2c6c7d58b 31 pc.printf("%s",&msg);
joon874 0:22832bff21a1 32 bt.printf("%s",msg);
joon874 0:22832bff21a1 33 }
joon874 0:22832bff21a1 34
joon874 0:22832bff21a1 35 /* Bluetooth to WIZwiki-W7500 */
joon874 0:22832bff21a1 36 if(bt.readable())
joon874 0:22832bff21a1 37 {
joon874 0:22832bff21a1 38 ch = bt.getc();
joon874 0:22832bff21a1 39 pc.putc(ch);
joon874 0:22832bff21a1 40
joon874 0:22832bff21a1 41 /* Control 3 colors LED */
joon874 0:22832bff21a1 42 if(ch == 'r'){
joon874 0:22832bff21a1 43 RED = !RED;
joon874 0:22832bff21a1 44 /* Notice RED LED condition to Bluethooth */
Tuxitheone 1:eec2c6c7d58b 45 if(RED == 0) bt.printf("RED OFF\n\r");
Tuxitheone 1:eec2c6c7d58b 46 else bt.printf("RED ON\n\r");
joon874 0:22832bff21a1 47 }else if(ch == 'g'){
joon874 0:22832bff21a1 48 GREEN = !GREEN;
joon874 0:22832bff21a1 49 /* Notice GREEN LED condition to Bluethooth */
Tuxitheone 1:eec2c6c7d58b 50 if(GREEN == 0) bt.printf("GREEN OFF\n\r");
Tuxitheone 1:eec2c6c7d58b 51 else bt.printf("GREEN ON\n\r");
joon874 0:22832bff21a1 52 }else if(ch == 'b'){
joon874 0:22832bff21a1 53 BLUE = !BLUE;
joon874 0:22832bff21a1 54 /* Notice BLUE LED condition to Bluethooth */
Tuxitheone 1:eec2c6c7d58b 55 if(BLUE == 0) bt.printf("BLUE OFF\n\r");
Tuxitheone 1:eec2c6c7d58b 56 else bt.printf("BLUE ON\n\r");
joon874 0:22832bff21a1 57 }
joon874 0:22832bff21a1 58 }
joon874 0:22832bff21a1 59
joon874 0:22832bff21a1 60 }
joon874 0:22832bff21a1 61 }