/////////////////////////////////// // // lab3_base project // // created 7/8/21 by tj // rev 0 // /////////////////////////////////// // // Base program for Lab3 // // This codes controls an external LED on and off // using an external button // and prints on or off to the console // // The external LED is connected to D4 // The external button is connected to D5 // // Inputs: external button - with pull-up // Outputs: external LED // ///////////////////////////////////////////// #include "mbed.h" #include // only needed when printing // Global HARDWARE Objects // create the LED object tied to D4 DigitalOut MyLED(D4); // create the button object tied to D5 DigitalIn MyButton(D5); int main(void){ setbuf(stdout, NULL); // disable buffering when printing // splash printf("\n\nlab3_base\n"); printf("Using Mbed OS version %d.%d.%d\n\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION); // working variables uint8_t button_val; // print header info printf("led\n"); // run an infinite loop while(1){ // read the current button value button_val = MyButton.read(); // turn the LED on or off if(button_val == 0){ // pushed MyLED.write(1); printf("on "); }else{ MyLED.write(0); printf("off"); }// end if // return to the beginning of the line // so that the text stays on a single line // otherwise it would scroll super fast printf("\r"); }// end while return 0; }// end main