Control 3 colors LED with Serial to Bluetooth(HC-05) on WIZwiki-W7500 paltform

Dependencies:   mbed

Prerequisite

This example is to control LEDs using bluetooth.

To implement this function, you need a Platform board, XBee Shield, XBee Bluetooth module.

Below are what we used.


Hardware Configuration

WIZwiki-W7500 Pin map

pin map


Software

main.cpp

include "mbed.h"

/* Digital Out Pin Configuration */
DigitalOut RED(LED_RED,1);
DigitalOut GREEN(LED_GREEN,1);
DigitalOut BLUE(LED_BLUE,1);

/* UART Pin Configuration */
Serial pc(USBTX, USBRX);    
Serial bt(D1,D0);           


int main(void)
{   
    /* baudrate configuration */
    pc.baud(115200);
    bt.baud(9600);
    
    pc.printf("WIZwiki-W7500 BT\n\r");
    
    char ch;
    char msg[256];
    
    while(1)
    {
        /* WIZwiki-W7500 to Bluetooth */
        if(pc.readable())
        {
            pc.scanf("%s",&msg);
            bt.printf("%s",msg);
        }
        
        /* Bluetooth to WIZwiki-W7500 */
        if(bt.readable())
        {
            ch = bt.getc();
            pc.putc(ch);
            
            /* Control 3 colors LED */
            if(ch == 'r'){
                RED = !RED;
                /* Notice RED LED condition to Bluethooth */
                if(RED == 0)    bt.printf("RED ON");
                else            bt.printf("RED OFF");
            }else if(ch == 'g'){
                GREEN = !GREEN;
                /* Notice GREEN LED condition to Bluethooth */
                if(GREEN == 0)    bt.printf("GREEN ON");
                else              bt.printf("GREEN OFF");
            }else if(ch == 'b'){
                BLUE = !BLUE;
                /* Notice BLUE LED condition to Bluethooth */
                if(BLUE == 0)    bt.printf("BLUE ON");
                else             bt.printf("BLUE OFF");
            }
        }
        
    }
}

Images

/media/uploads/bingdo/serial_to_bluetooth_helloworld_wizwiki-w7500.jpg

Test by Android App
/media/uploads/bingdo/serial_to_bluetooth_helloworld_wizwiki-w7500_2.png


Committer:
joon874
Date:
Tue Feb 02 08:05:34 2016 +0000
Revision:
0:22832bff21a1
Serial to Bluetooth helloworld for WIZnet academy

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 */
joon874 0:22832bff21a1 4 DigitalOut RED(D8,1);
joon874 0:22832bff21a1 5 DigitalOut GREEN(D9,1);
joon874 0:22832bff21a1 6 DigitalOut BLUE(D10,1);
joon874 0:22832bff21a1 7
joon874 0:22832bff21a1 8 /* UART Pin Configuration */
joon874 0:22832bff21a1 9 Serial pc(USBTX, USBRX);
joon874 0:22832bff21a1 10 Serial bt(D1,D0);
joon874 0:22832bff21a1 11
joon874 0:22832bff21a1 12
joon874 0:22832bff21a1 13 int main(void)
joon874 0:22832bff21a1 14 {
joon874 0:22832bff21a1 15 /* baudrate configuration */
joon874 0:22832bff21a1 16 pc.baud(115200);
joon874 0:22832bff21a1 17 bt.baud(9600);
joon874 0:22832bff21a1 18
joon874 0:22832bff21a1 19 pc.printf("WIZwiki-W7500 BT\n\r");
joon874 0:22832bff21a1 20
joon874 0:22832bff21a1 21 char ch;
joon874 0:22832bff21a1 22 char msg[256];
joon874 0:22832bff21a1 23
joon874 0:22832bff21a1 24 while(1)
joon874 0:22832bff21a1 25 {
joon874 0:22832bff21a1 26 /* WIZwiki-W7500 to Bluetooth */
joon874 0:22832bff21a1 27 if(pc.readable())
joon874 0:22832bff21a1 28 {
joon874 0:22832bff21a1 29 pc.scanf("%s",&msg);
joon874 0:22832bff21a1 30 bt.printf("%s",msg);
joon874 0:22832bff21a1 31 }
joon874 0:22832bff21a1 32
joon874 0:22832bff21a1 33 /* Bluetooth to WIZwiki-W7500 */
joon874 0:22832bff21a1 34 if(bt.readable())
joon874 0:22832bff21a1 35 {
joon874 0:22832bff21a1 36 ch = bt.getc();
joon874 0:22832bff21a1 37 pc.putc(ch);
joon874 0:22832bff21a1 38
joon874 0:22832bff21a1 39 /* Control 3 colors LED */
joon874 0:22832bff21a1 40 if(ch == 'r'){
joon874 0:22832bff21a1 41 RED = !RED;
joon874 0:22832bff21a1 42 /* Notice RED LED condition to Bluethooth */
joon874 0:22832bff21a1 43 if(RED == 0) bt.printf("RED ON");
joon874 0:22832bff21a1 44 else bt.printf("RED OFF");
joon874 0:22832bff21a1 45 }else if(ch == 'g'){
joon874 0:22832bff21a1 46 GREEN = !GREEN;
joon874 0:22832bff21a1 47 /* Notice GREEN LED condition to Bluethooth */
joon874 0:22832bff21a1 48 if(GREEN == 0) bt.printf("GREEN ON");
joon874 0:22832bff21a1 49 else bt.printf("GREEN OFF");
joon874 0:22832bff21a1 50 }else if(ch == 'b'){
joon874 0:22832bff21a1 51 BLUE = !BLUE;
joon874 0:22832bff21a1 52 /* Notice BLUE LED condition to Bluethooth */
joon874 0:22832bff21a1 53 if(BLUE == 0) bt.printf("BLUE ON");
joon874 0:22832bff21a1 54 else bt.printf("BLUE OFF");
joon874 0:22832bff21a1 55 }
joon874 0:22832bff21a1 56 }
joon874 0:22832bff21a1 57
joon874 0:22832bff21a1 58 }
joon874 0:22832bff21a1 59 }