#include "mbed.h" // SPST Pushbutton demo using internal PullDown function // no external pull-down resistor needed // Connect pushbutton from P8 to VOUT (VDD) // Connect P21 to an LED DigitalOut myled1(LED1); //LEDs for display DigitalOut myled2(LED2); DigitalOut myled3(LED3); DigitalOut myled4(LED4); DigitalIn pb(p8); //A pin to connect to a button PwmOut variableled(p21); //A modulated pin for a variable brighness LED void turnOn (int led); //Function prototypes void turnOff (int led); int main() { pb.mode(PullDown); //Set button to PullDown mode int led = 1; //Start with LED1 while(1) { if (pb){ //Button pressed turnOn(led); //Turn the current LED on variableled = 1.0/led; //Set the brightness of the variable LED wait(0.1); //Allow 0.1 sec for button debounce while (pb); //Wait until button not pressed turnOff(led); //Turn off the LED variableled = 0.0; //Turn off variable LED wait(0.1); //Allow 0.1 sec for button debounce {if (led == 4) led = 1; else led++;} //Cycle back to LED1 } } } void turnOn (int led) { //Turns on the specified LED switch (led) { case 1 : myled1 = 1; break; case 2 : myled2 = 1; break; case 3 : myled3 = 1; break; case 4 : myled4 = 1; break; } } void turnOff (int led) { //Turns off the specified LED switch (led) { case 1 : myled1 = 0; break; case 2 : myled2 = 0; break; case 3 : myled3 = 0; break; case 4 : myled4 = 0; break; } }