reading an interrupt

Dependencies:   Hotboards_switches mbed

Committer:
RomanValenciaP
Date:
Tue Mar 15 18:40:42 2016 +0000
Revision:
1:ce1c787ed6fd
Parent:
0:6e25e921deef
Child:
2:d4a7439b72dd
added header info

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RomanValenciaP 0:6e25e921deef 1
RomanValenciaP 1:ce1c787ed6fd 2 /* Library: Hotboards_switches.h
RomanValenciaP 1:ce1c787ed6fd 3 * Project: input
RomanValenciaP 1:ce1c787ed6fd 4 * File: main.cpp
RomanValenciaP 1:ce1c787ed6fd 5 * Author: Román Valencia
RomanValenciaP 1:ce1c787ed6fd 6 *
RomanValenciaP 0:6e25e921deef 7 * The simplest program, read an input on pin PB_4
RomanValenciaP 0:6e25e921deef 8 */
RomanValenciaP 0:6e25e921deef 9
RomanValenciaP 0:6e25e921deef 10 #include "mbed.h"
RomanValenciaP 0:6e25e921deef 11 #include "Hotboards_switches.h"
RomanValenciaP 0:6e25e921deef 12
RomanValenciaP 0:6e25e921deef 13 // Creates a single sw object, this interrupt will give us a LOW(0) value when close
RomanValenciaP 0:6e25e921deef 14 // because our dip switch works with pull-ups
RomanValenciaP 0:6e25e921deef 15 Hotboards_switches sw( PB_4 );
RomanValenciaP 0:6e25e921deef 16 // If your dip switch will gave you a HIGH(1) value when close, then we need to create
RomanValenciaP 0:6e25e921deef 17 // the sw object with an extra parameter: Hotboards_switches sw( PB_4 , 1 );
RomanValenciaP 0:6e25e921deef 18 // In any case the function will return a HIGH(1) value any time the sw is closed
RomanValenciaP 0:6e25e921deef 19
RomanValenciaP 0:6e25e921deef 20 //For this example we will use the USB serial port, here we initialize it
RomanValenciaP 0:6e25e921deef 21 Serial pc(USBTX,USBRX);
RomanValenciaP 0:6e25e921deef 22
RomanValenciaP 0:6e25e921deef 23 int main()
RomanValenciaP 0:6e25e921deef 24 {
RomanValenciaP 0:6e25e921deef 25 while(1)
RomanValenciaP 0:6e25e921deef 26 {
RomanValenciaP 0:6e25e921deef 27 // When the interrupt is close (or ON) the function will return a true value
RomanValenciaP 0:6e25e921deef 28 // it doesn´t matter if our input is configured with pull-ups(LOW) or
RomanValenciaP 0:6e25e921deef 29 // pull-downs(HIGH)
RomanValenciaP 0:6e25e921deef 30 if( sw.read() )
RomanValenciaP 0:6e25e921deef 31 {
RomanValenciaP 0:6e25e921deef 32 pc.printf( "sw = close (on)\n\r" );
RomanValenciaP 0:6e25e921deef 33 }
RomanValenciaP 0:6e25e921deef 34 else
RomanValenciaP 0:6e25e921deef 35 {
RomanValenciaP 0:6e25e921deef 36 pc.printf( "sw = open (off)\n\r" );
RomanValenciaP 0:6e25e921deef 37 }
RomanValenciaP 0:6e25e921deef 38 // Wait 1 second, just to not query so often
RomanValenciaP 0:6e25e921deef 39 wait( 1 );
RomanValenciaP 0:6e25e921deef 40 }
RomanValenciaP 0:6e25e921deef 41 }