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
Fork of input by
main.cpp
00001 00002 00003 // modified 4-march-2016 by Pedro 00004 /* 00005 * The simplest program, read an input on pin PB_4 00006 */ 00007 00008 #include "mbed.h" 00009 #include "Hotboards_switches.h" 00010 00011 // Creates a single sw object, this interrupt will give us a LOW(0) value when close 00012 // because our dip switch works with pull-ups 00013 Hotboards_switches sw( PB_4 ); 00014 // If your dip switch will gave you a HIGH(1) value when close, then we need to create 00015 // the sw object with an extra parameter: Hotboards_switches sw( PB_4 , 1 ); 00016 // In any case the function will return a HIGH(1) value any time the sw is closed 00017 00018 //For this example we will use the USB serial port, here we initialize it 00019 Serial pc(USBTX,USBRX); 00020 00021 int main() 00022 { 00023 while(1) 00024 { 00025 // When the interrupt is close (or ON) the function will return a true value 00026 // it doesn´t matter if our input is configured with pull-ups(LOW) or 00027 // pull-downs(HIGH) 00028 if( sw.read() ) 00029 { 00030 pc.printf( "sw = close (on)\n\r" ); 00031 } 00032 else 00033 { 00034 pc.printf( "sw = open (off)\n\r" ); 00035 } 00036 // Wait 1 second, just to not query so often 00037 wait( 1 ); 00038 } 00039 }
Generated on Tue Jul 12 2022 21:48:54 by
