Hotboards MX / Mbed 2 deprecated Hotboards_Switches_Read_single

Dependencies:   Hotboards_switches mbed

Fork of input by Roman Valencia

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 
00002 /* Library:     Hotboards_switches.h
00003  * Project:     input
00004  * File:        main.cpp
00005  * Author:      Diego Perez
00006  * Modified by: Roman Valencia 
00007  * Contact:     http://www.hotboards.org/
00008  *
00009  * The simplest program, read an input on pin PB_4
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         // When the interrupt is close (or ON) the function will return a true value
00030         // it doesn´t matter if our input is configured with pull-ups(LOW) or
00031         // pull-downs(HIGH)
00032         if( sw.read() )
00033         {
00034             pc.printf( "sw = close (on)\n\r" );
00035         }
00036         else
00037         {
00038             pc.printf( "sw = open (off)\n\r" );
00039         }
00040         // Wait 1 second, just to not query so often
00041         wait( 1 );
00042     }
00043 }