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