Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Hotboards_switches mbed
main.cpp
00001 00002 /* Library: Hotboards_switches.h 00003 * Project: input_change 00004 * File: main.cpp 00005 * Author: Diego Perez 00006 * Modified by: Roman Valencia 00007 * Contact: http://www.hotboards.org/ 00008 * 00009 * Reads an input on pin PB_4, only when its value has been changed 00010 */ 00011 00012 #include "mbed.h" 00013 #include "Hotboards_switches.h" 00014 00015 // Creates a single sw object, this interrupt will give us a LOW(0) value when close 00016 // because our dip switch works with pull-ups 00017 Hotboards_switches sw( PB_4 ); 00018 // If your dip switch will gave you a HIGH(1) value when close, then we need to create 00019 // the sw object with an extra parameter: Hotboards_switches sw( PB_4 , 1 ); 00020 // In any case the function will return a HIGH(1) value any time the sw is closed 00021 00022 // For this example we will use the USB serial port, here we initialize it 00023 Serial pc(USBTX,USBRX); 00024 00025 int main() 00026 { 00027 while(1) 00028 { 00029 //Asks when the interrupt changes its value 00030 if( sw.hasItChange( ) ) 00031 { 00032 // When the interrupt is close (or ON) the function will return a true value 00033 // it doesn´t matter if our input is configured with pull-ups(LOW) or 00034 // pull-downs(HIGH) 00035 if( sw.read( ) ) 00036 { 00037 pc.printf( "sw = close (on)\n\r" ); 00038 } 00039 else 00040 { 00041 pc.printf( "sw = open (off)\n\r" ); 00042 } 00043 // Wait 250 ms, just to not query so often 00044 wait_ms( 250 ); 00045 } 00046 } 00047 }
Generated on Thu Jul 14 2022 20:42:19 by
1.7.2