fork test from roman's input code
Dependencies: Hotboards_switches mbed
Fork of input by
main.cpp@0:6e25e921deef, 2016-03-02 (annotated)
- Committer:
- RomanValenciaP
- Date:
- Wed Mar 02 20:30:43 2016 +0000
- Revision:
- 0:6e25e921deef
- Child:
- 1:d8aefd9790ea
first release - recquires approval
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RomanValenciaP | 0:6e25e921deef | 1 | |
RomanValenciaP | 0:6e25e921deef | 2 | /* |
RomanValenciaP | 0:6e25e921deef | 3 | * The simplest program, read an input on pin PB_4 |
RomanValenciaP | 0:6e25e921deef | 4 | */ |
RomanValenciaP | 0:6e25e921deef | 5 | |
RomanValenciaP | 0:6e25e921deef | 6 | #include "mbed.h" |
RomanValenciaP | 0:6e25e921deef | 7 | #include "Hotboards_switches.h" |
RomanValenciaP | 0:6e25e921deef | 8 | |
RomanValenciaP | 0:6e25e921deef | 9 | // Creates a single sw object, this interrupt will give us a LOW(0) value when close |
RomanValenciaP | 0:6e25e921deef | 10 | // because our dip switch works with pull-ups |
RomanValenciaP | 0:6e25e921deef | 11 | Hotboards_switches sw( PB_4 ); |
RomanValenciaP | 0:6e25e921deef | 12 | // If your dip switch will gave you a HIGH(1) value when close, then we need to create |
RomanValenciaP | 0:6e25e921deef | 13 | // the sw object with an extra parameter: Hotboards_switches sw( PB_4 , 1 ); |
RomanValenciaP | 0:6e25e921deef | 14 | // In any case the function will return a HIGH(1) value any time the sw is closed |
RomanValenciaP | 0:6e25e921deef | 15 | |
RomanValenciaP | 0:6e25e921deef | 16 | //For this example we will use the USB serial port, here we initialize it |
RomanValenciaP | 0:6e25e921deef | 17 | Serial pc(USBTX,USBRX); |
RomanValenciaP | 0:6e25e921deef | 18 | |
RomanValenciaP | 0:6e25e921deef | 19 | int main() |
RomanValenciaP | 0:6e25e921deef | 20 | { |
RomanValenciaP | 0:6e25e921deef | 21 | while(1) |
RomanValenciaP | 0:6e25e921deef | 22 | { |
RomanValenciaP | 0:6e25e921deef | 23 | // When the interrupt is close (or ON) the function will return a true value |
RomanValenciaP | 0:6e25e921deef | 24 | // it doesn´t matter if our input is configured with pull-ups(LOW) or |
RomanValenciaP | 0:6e25e921deef | 25 | // pull-downs(HIGH) |
RomanValenciaP | 0:6e25e921deef | 26 | if( sw.read() ) |
RomanValenciaP | 0:6e25e921deef | 27 | { |
RomanValenciaP | 0:6e25e921deef | 28 | pc.printf( "sw = close (on)\n\r" ); |
RomanValenciaP | 0:6e25e921deef | 29 | } |
RomanValenciaP | 0:6e25e921deef | 30 | else |
RomanValenciaP | 0:6e25e921deef | 31 | { |
RomanValenciaP | 0:6e25e921deef | 32 | pc.printf( "sw = open (off)\n\r" ); |
RomanValenciaP | 0:6e25e921deef | 33 | } |
RomanValenciaP | 0:6e25e921deef | 34 | // Wait 1 second, just to not query so often |
RomanValenciaP | 0:6e25e921deef | 35 | wait( 1 ); |
RomanValenciaP | 0:6e25e921deef | 36 | } |
RomanValenciaP | 0:6e25e921deef | 37 | } |