Héctor Segnorile / Mbed 2 deprecated frdm_ledRGB

Dependencies:   mbed

Committer:
segnoh
Date:
Mon Aug 10 00:13:19 2015 +0000
Revision:
1:83391eec9fef
Parent:
0:55150494d6db
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
segnoh 0:55150494d6db 9 int check_sw2(int choice)
segnoh 0:55150494d6db 10 {
segnoh 0:55150494d6db 11 if(sw2 == 0)
segnoh 0:55150494d6db 12 {
segnoh 0:55150494d6db 13 switch(choice)
segnoh 0:55150494d6db 14 {
segnoh 0:55150494d6db 15 case 0:
segnoh 0:55150494d6db 16 led_red = 0;
segnoh 0:55150494d6db 17 led_green = 1;
segnoh 0:55150494d6db 18 break;
segnoh 0:55150494d6db 19 case 1:
segnoh 0:55150494d6db 20 led_red = 1;
segnoh 0:55150494d6db 21 led_green = 0;
segnoh 0:55150494d6db 22 break;
segnoh 0:55150494d6db 23 case 2:
segnoh 0:55150494d6db 24 led_red = 0;
segnoh 0:55150494d6db 25 led_green = 0;
segnoh 0:55150494d6db 26 break;
segnoh 0:55150494d6db 27 case 3:
segnoh 0:55150494d6db 28 led_red = 1;
segnoh 0:55150494d6db 29 led_green = 1;
segnoh 0:55150494d6db 30 break;
segnoh 0:55150494d6db 31 }
segnoh 0:55150494d6db 32 choice++;
segnoh 0:55150494d6db 33 if(choice > 3) choice = 0;
segnoh 0:55150494d6db 34 }
segnoh 0:55150494d6db 35 return choice;
segnoh 0:55150494d6db 36 }
segnoh 0:55150494d6db 37
segnoh 0:55150494d6db 38 void check_sw3(DigitalOut led_status)
segnoh 0:55150494d6db 39 {
segnoh 0:55150494d6db 40 if(sw3 == 0)
segnoh 0:55150494d6db 41 {
segnoh 0:55150494d6db 42 if(led_status) led_blue = 0;
segnoh 0:55150494d6db 43 else led_blue = 1;
segnoh 0:55150494d6db 44 }
segnoh 0:55150494d6db 45 }
segnoh 0:55150494d6db 46
segnoh 0:55150494d6db 47 int main()
segnoh 0:55150494d6db 48 {
segnoh 0:55150494d6db 49 int choice = 0;
segnoh 0:55150494d6db 50
segnoh 0:55150494d6db 51 led_green = 1;
segnoh 0:55150494d6db 52 led_red = 1;
segnoh 0:55150494d6db 53 led_blue = 1;
segnoh 0:55150494d6db 54
segnoh 0:55150494d6db 55 while(true)
segnoh 0:55150494d6db 56 {
segnoh 0:55150494d6db 57 choice = check_sw2(choice);
segnoh 0:55150494d6db 58 check_sw3(led_blue);
segnoh 0:55150494d6db 59 wait(0.3);
segnoh 0:55150494d6db 60 }
segnoh 0:55150494d6db 61 }