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.
main.cpp
00001 /* Test of FRDM-KL25z RGB LED and Serial out to PC. 00002 * This program blinks the LED through the series of colors 00003 * red, greeen, and blue, displaying each for 1 second, with 00004 * a 1 second off period between each color. As it makes each 00005 * change in the status of the LED, it sends a message to the 00006 * pc serial port over the USB programming connection. The 00007 * pattern repeats 5 times, then two short white flashes are 00008 * displayed by turning all threee LEDs on and off at once, and 00009 * a final message is sent to the serial port. 00010 * 00011 * Tested from OSX 10.8.4. To find the serial port device, 00012 * launch Terminal, then type: 00013 * 00014 * ls /dev/tty.usbmodem* 00015 * 00016 * It will return something like /dev/tty.usbmodem1d22 00017 * To change Terminal to connect to the serial port, use the screen 00018 * command, specifying the path returned by ls and the baud rate: 00019 * 00020 * screen /dev/tty.usbmodem1d22 9600 00021 * 00022 * As a shortcut, if you have just one serial device connected, you 00023 * can skip the first command and type the second command as far as 00024 * tty.usb and hit the tab key and it will autocomplete. 00025 * Once screen is running, type Ctrl-a then ? for a list of available 00026 * commands. 00027 */ 00028 00029 #include "mbed.h" 00030 00031 DigitalOut redLED(LED_RED); // Define digital outputs for each LED color 00032 DigitalOut greenLED(LED_GREEN); 00033 DigitalOut blueLED(LED_BLUE); 00034 Serial pc(USBTX, USBRX); // Declare the serial port 00035 00036 int main() { 00037 pc.baud (9600); // Set the baud rate for the serial connection 00038 redLED = 1; // This a common anode RGB LED, with the anodes connected 00039 greenLED = 1; // to 1. Thus, to turn a color off you counterintuitively set 00040 blueLED = 1; // it to 1, so there is no voltage difference across the LED 00041 for (int i = 1; i <= 5; i++) { // Do 5 times: 00042 redLED = 0; // Turn the red LED on 00043 pc.printf("Red LED ON \n\r"); // Send a status message 00044 wait(1.0); // Wait 1.0 seconds 00045 redLED = 1; // Turn the red LED off 00046 pc.printf("Red LED OFF \n\r"); // Send a status message 00047 wait(1.0); // Wait 1.0 seconds 00048 greenLED = 0; // Repeat the above for the green LED 00049 pc.printf("Green LED ON \n\r"); 00050 wait(1.0); 00051 greenLED = 1; 00052 pc.printf("Green LED OFF \n\r"); 00053 wait(1.0); 00054 blueLED = 0; // Repeat for the blue LED 00055 pc.printf("Blue LED ON \n\r"); 00056 wait(1.0); 00057 blueLED = 1; 00058 pc.printf("Blue LED OFF \n\r"); 00059 wait(1.0); 00060 } 00061 redLED = greenLED = blueLED = 0; // Give a short double-flash of white 00062 wait(0.25); 00063 redLED = greenLED = blueLED = 1; 00064 wait(0.25); 00065 redLED = greenLED = blueLED = 0; 00066 wait(0.25); 00067 redLED = greenLED = blueLED = 1; // Leave the LED off at the end 00068 pc.printf("Goodbye \n\r"); // Send a farewell message 00069 }
Generated on Fri Aug 5 2022 11:14:07 by
1.7.2