Héctor Segnorile / Mbed 2 deprecated frdm_ledRGB

Dependencies:   mbed

Committer:
segnoh
Date:
Mon Aug 10 00:05:27 2015 +0000
Revision:
0:55150494d6db
Child:
1:83391eec9fef
Switch ON/OFF the RGB leds

Who changed what in which revision?

UserRevisionLine numberNew contents of line
segnoh 0:55150494d6db 1 #include "mbed.h"
segnoh 0:55150494d6db 2
segnoh 0:55150494d6db 3 DigitalOut led_red(LED_RED);
segnoh 0:55150494d6db 4 DigitalOut led_green(LED_GREEN);
segnoh 0:55150494d6db 5 DigitalOut led_blue(LED_BLUE);
segnoh 0:55150494d6db 6 DigitalIn sw2(SW2);
segnoh 0:55150494d6db 7 DigitalIn sw3(SW3);
segnoh 0:55150494d6db 8 Serial pc(USBTX, USBRX);
segnoh 0:55150494d6db 9
segnoh 0:55150494d6db 10 int check_sw2(int choice)
segnoh 0:55150494d6db 11 {
segnoh 0:55150494d6db 12 if(sw2 == 0)
segnoh 0:55150494d6db 13 {
segnoh 0:55150494d6db 14 pc.printf("SW2 button pressed. \n");
segnoh 0:55150494d6db 15 switch(choice)
segnoh 0:55150494d6db 16 {
segnoh 0:55150494d6db 17 case 0:
segnoh 0:55150494d6db 18 led_red = 0;
segnoh 0:55150494d6db 19 led_green = 1;
segnoh 0:55150494d6db 20 break;
segnoh 0:55150494d6db 21 case 1:
segnoh 0:55150494d6db 22 led_red = 1;
segnoh 0:55150494d6db 23 led_green = 0;
segnoh 0:55150494d6db 24 break;
segnoh 0:55150494d6db 25 case 2:
segnoh 0:55150494d6db 26 led_red = 0;
segnoh 0:55150494d6db 27 led_green = 0;
segnoh 0:55150494d6db 28 break;
segnoh 0:55150494d6db 29 case 3:
segnoh 0:55150494d6db 30 led_red = 1;
segnoh 0:55150494d6db 31 led_green = 1;
segnoh 0:55150494d6db 32 break;
segnoh 0:55150494d6db 33 }
segnoh 0:55150494d6db 34 choice++;
segnoh 0:55150494d6db 35 if(choice > 3) choice = 0;
segnoh 0:55150494d6db 36 }
segnoh 0:55150494d6db 37 return choice;
segnoh 0:55150494d6db 38 }
segnoh 0:55150494d6db 39
segnoh 0:55150494d6db 40 void check_sw3(DigitalOut led_status)
segnoh 0:55150494d6db 41 {
segnoh 0:55150494d6db 42 if(sw3 == 0)
segnoh 0:55150494d6db 43 {
segnoh 0:55150494d6db 44 pc.printf("SW3 button pressed. \n");
segnoh 0:55150494d6db 45 if(led_status) led_blue = 0;
segnoh 0:55150494d6db 46 else led_blue = 1;
segnoh 0:55150494d6db 47 }
segnoh 0:55150494d6db 48 }
segnoh 0:55150494d6db 49
segnoh 0:55150494d6db 50 int main()
segnoh 0:55150494d6db 51 {
segnoh 0:55150494d6db 52 int choice = 0;
segnoh 0:55150494d6db 53
segnoh 0:55150494d6db 54 led_green = 1;
segnoh 0:55150494d6db 55 led_red = 1;
segnoh 0:55150494d6db 56 led_blue = 1;
segnoh 0:55150494d6db 57
segnoh 0:55150494d6db 58 pc.baud(115200);
segnoh 0:55150494d6db 59 pc.printf("Hello World from FRDM-K64F board.\n");
segnoh 0:55150494d6db 60
segnoh 0:55150494d6db 61 while(true)
segnoh 0:55150494d6db 62 {
segnoh 0:55150494d6db 63 choice = check_sw2(choice);
segnoh 0:55150494d6db 64 check_sw3(led_blue);
segnoh 0:55150494d6db 65 wait(0.3);
segnoh 0:55150494d6db 66 }
segnoh 0:55150494d6db 67 }