Serial and RGB LED program example for Hexiwear
This project demonstrates the use of a Hexiwear Serial interface and the GPIOs to control the RGB LED
Open a Hyperterminal tool on your computer and connect it to the "mbed Serial port (COMxx)" with Baud rate "9600bps"
Compile the project and copy the binary "Hexi_Serial_RGB_Example_HEXIWEAR.bin" in the DAP-LINK drive from your computer file explorer Press the K64F-RESET button on the docking station to start the program on your board
Message "Tell me the RGB LED Color" will appear in the Hyperterminal window Then every 1s a color (Red, Green or Blue) will be displayed in the Hyperterminal window and the RGB LED will power-on accordingly
main.cpp@0:ec68cfbf0495, 2016-08-15 (annotated)
- Committer:
- GregC
- Date:
- Mon Aug 15 18:15:42 2016 +0000
- Revision:
- 0:ec68cfbf0495
Serial and RGB LED program example for Hexiwear
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GregC | 0:ec68cfbf0495 | 1 | #include "mbed.h" |
GregC | 0:ec68cfbf0495 | 2 | #include "rtos.h" |
GregC | 0:ec68cfbf0495 | 3 | |
GregC | 0:ec68cfbf0495 | 4 | DigitalOut led_red(PTC8); |
GregC | 0:ec68cfbf0495 | 5 | DigitalOut led_green(PTD0); |
GregC | 0:ec68cfbf0495 | 6 | DigitalOut led_blue(PTC9); |
GregC | 0:ec68cfbf0495 | 7 | Serial pc(USBTX, USBRX); |
GregC | 0:ec68cfbf0495 | 8 | |
GregC | 0:ec68cfbf0495 | 9 | int main() |
GregC | 0:ec68cfbf0495 | 10 | { |
GregC | 0:ec68cfbf0495 | 11 | pc.printf("Tell me the RGB LED Color\r\n"); |
GregC | 0:ec68cfbf0495 | 12 | |
GregC | 0:ec68cfbf0495 | 13 | while (true) { |
GregC | 0:ec68cfbf0495 | 14 | pc.printf("Red\r\n"); // print the value of variable i |
GregC | 0:ec68cfbf0495 | 15 | led_red=0; |
GregC | 0:ec68cfbf0495 | 16 | led_green=1; |
GregC | 0:ec68cfbf0495 | 17 | led_blue=1; |
GregC | 0:ec68cfbf0495 | 18 | Thread::wait(1000); // wait a small period of time |
GregC | 0:ec68cfbf0495 | 19 | pc.printf("Green\r\n"); // print the value of variable i |
GregC | 0:ec68cfbf0495 | 20 | led_red=1; |
GregC | 0:ec68cfbf0495 | 21 | led_green=0; |
GregC | 0:ec68cfbf0495 | 22 | led_blue=1; |
GregC | 0:ec68cfbf0495 | 23 | Thread::wait(1000); // wait a small period of time |
GregC | 0:ec68cfbf0495 | 24 | pc.printf("Blue\r\n"); // print the value of variable i |
GregC | 0:ec68cfbf0495 | 25 | led_red=1; |
GregC | 0:ec68cfbf0495 | 26 | led_green=1; |
GregC | 0:ec68cfbf0495 | 27 | led_blue=0; |
GregC | 0:ec68cfbf0495 | 28 | Thread::wait(1000); // wait a small period of time |
GregC | 0:ec68cfbf0495 | 29 | |
GregC | 0:ec68cfbf0495 | 30 | } |
GregC | 0:ec68cfbf0495 | 31 | } |
GregC | 0:ec68cfbf0495 | 32 |