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


Files at this revision

API Documentation at this revision

Comitter:
joon874
Date:
Tue Feb 02 08:05:34 2016 +0000
Commit message:
Serial to Bluetooth helloworld for WIZnet academy

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 22832bff21a1 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Feb 02 08:05:34 2016 +0000
@@ -0,0 +1,59 @@
+#include "mbed.h"
+
+/* Digital Out Pin Configuration */
+DigitalOut RED(D8,1);
+DigitalOut GREEN(D9,1);
+DigitalOut BLUE(D10,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");
+            }
+        }
+        
+    }
+}
diff -r 000000000000 -r 22832bff21a1 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Feb 02 08:05:34 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/6f327212ef96
\ No newline at end of file