Toggle led ON pin PA_5 (LED1) when the button on pin PB_4 is released
Dependencies: Hotboards_buttons mbed
main.cpp
00001 00002 /* 00003 * Toggle led ON pin PA_5 (LED1) when the button on pin PB_4 is released 00004 */ 00005 00006 #include "mbed.h" 00007 #include "Hotboards_buttons.h" 00008 00009 //Creates a single button object, when the button is pressed it gives you 00010 //a LOW(0) value because it works with pull-ups. 00011 Hotboards_buttons btn( PB_4 ); 00012 //If your buttons gives you a HIGH(1) value when is pressed, then we need 00013 //to create the button object with and extra parameter: 00014 //Hotboards_buttons btn( PB_4 , 1 ); in any case the functions will return 00015 //a HIGH(1) value any time the button is pressed 00016 00017 //To our example we will use the led on the nucleo board 00018 DigitalOut nucleoLed( LED1 ); 00019 00020 int main() 00021 { 00022 while(1) 00023 { 00024 //The moment when the button is released the function will return a HIGH(1) 00025 //value, it doesn`t matter if your button is configured with pull-ups(LOW) 00026 //or pull-downs(HIGH) 00027 if( btn.isReleased( ) ) 00028 { 00029 //Toggle led on the nucleo board 00030 nucleoLed = !nucleoLed; 00031 } 00032 } 00033 }
Generated on Tue Jul 26 2022 09:18:17 by 1.7.2