/*############################################################# Program Name : ex6_sw_leds_truth Author : Grant Phillips Date Modified : 12/01/2016 Compiler : ARMmbed Tested On : STM32F4-Discovery Description : Reads the value of 3 switches and then controls the output of 8 LEDs as follows: SW2 SW1 SW0 LEDs (0=OFF, 1=ON) 0 0 0 00000000 0 0 1 00001111 0 1 0 11110000 0 1 1 11111111 1 0 0 10101010 1 0 1 10101010 1 1 0 10101010 1 1 1 10101010 Requirements : * STM32F4-Discovery Board Circuit : * 8 LEDs connected to PD15 - PD8 * 3 switches connected to PE10(SW2), PE9(SW1) and PE8(SW0) with pullup resitors ##############################################################*/ #include "mbed.h" BusOut myleds(PD_8, PD_9, PD_10, PD_11, PD_12, PD_13, PD_14, PD_15); // bit0 bit1 bit2 bit3 bit4 bit5 bit6 bit7 . . . DigitalIn switch2(PE_10); DigitalIn switch1(PE_9); DigitalIn switch0(PE_8); int main() { uint8_t SW2, SW1, SW0; while(1) { /* due to the inverse logic of the input switch wiring, we need to invert the values read from the actual switches too to fit our truth table for this example */ SW2 = 1 - switch2; SW1 = 1 - switch1; SW0 = 1 - switch0; /* apply if..else for truth table outputs */ if((SW2==0) && (SW1==0) && (SW0==0)) myleds = 0x00; else if((SW2==0) && (SW1==0) && (SW0==1)) myleds = 0x0f; else if((SW2==0) && (SW1==1) && (SW0==0)) myleds = 0xf0; else if((SW2==0) && (SW1==1) && (SW0==1)) myleds = 0xff; else myleds = 0xaa; } }