Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 0:15af3fe682b0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Mar 26 10:19:41 2021 +0000 @@ -0,0 +1,34 @@ +#include "mbed.h" +#include "iostream" // this is required for "cin" (user input from keyboard) + +DigitalOut R(p23); //Red pin of RGB LED +DigitalOut G(p24); //Green pin of RGB LED +DigitalOut B(p25); //Blue pin of RGB LED + char c; // initialise a variable of type char for the user intput. +//*NOTE THE RGB LED on the application board is "0" for on, "1" for off * NOTE // + +int main() { + R = G = B = 1; + printf("Control the LED using keyboard. \n \r"); // print the messages below to terminal (\n = new line, \r = move to 1st pos on next line.) + printf("R for Red, G for Green, B for Blue,W for White. \n \r"); + printf("O turn off all LEDs. \n \r"); + while(1) { + + cin >> c; // get user input and assign to the char variable "c" + if + (c == 'r') // if input = r, for red... + {R = 0, G = 1, B = 1;} // turn red of RGB on, while turning Green & Blue off. ** SEE NOTE ABOVE ** + else if // if not the above... + (c == 'g') + {R = 1, G = 0, B = 1;} + else if // if not the above... + (c == 'b') + {R = 1, G = 1, B = 0;} + else if // if not the above... + (c == 'w') + {R = 0, G = 0, B = 0;} + else if // if not the above... + (c == 'o') + {R = 1, G = 1, B = 1;} + } +}