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