Read an analog pin using the MultiTech Dragonfly.
Dependencies: mbed
main.cpp@1:5805f92fc762, 2016-02-26 (annotated)
- Committer:
- mfiore
- Date:
- Fri Feb 26 16:42:56 2016 +0000
- Revision:
- 1:5805f92fc762
- Parent:
- 0:436a6a6b80a1
Updated mbed library to revision 112, disable regulator's battery charger
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mfiore | 0:436a6a6b80a1 | 1 | /** Dragonfly AnalogIn Example Program |
mfiore | 0:436a6a6b80a1 | 2 | * |
mfiore | 0:436a6a6b80a1 | 3 | * This program demonstrates how to read an anglog pin using the |
mfiore | 0:436a6a6b80a1 | 4 | * MultiTech Dragonfly and MultiTech UDK2 hardware. The only |
mfiore | 0:436a6a6b80a1 | 5 | * additional hardware required is an analog voltage source like |
mfiore | 0:436a6a6b80a1 | 6 | * a potentiometer. |
mfiore | 0:436a6a6b80a1 | 7 | * |
mfiore | 0:436a6a6b80a1 | 8 | * |
mfiore | 0:436a6a6b80a1 | 9 | * This program reads the analog input connected to pin A0 and |
mfiore | 0:436a6a6b80a1 | 10 | * prints the result. |
mfiore | 0:436a6a6b80a1 | 11 | */ |
mfiore | 0:436a6a6b80a1 | 12 | |
mfiore | 0:436a6a6b80a1 | 13 | #include "mbed.h" |
mfiore | 1:5805f92fc762 | 14 | |
mfiore | 1:5805f92fc762 | 15 | // This line controls the regulator's battery charger. |
mfiore | 1:5805f92fc762 | 16 | // BC_NCE = 0 enables the battery charger |
mfiore | 1:5805f92fc762 | 17 | // BC_NCE = 1 disables the battery charger |
mfiore | 1:5805f92fc762 | 18 | DigitalOut bc_nce(PB_2); |
mfiore | 0:436a6a6b80a1 | 19 | |
mfiore | 0:436a6a6b80a1 | 20 | int main() { |
mfiore | 1:5805f92fc762 | 21 | // Disable the battery charger unless a battery is attached. |
mfiore | 1:5805f92fc762 | 22 | bc_nce = 1; |
mfiore | 1:5805f92fc762 | 23 | |
mfiore | 0:436a6a6b80a1 | 24 | AnalogIn in(A0); |
mfiore | 0:436a6a6b80a1 | 25 | |
mfiore | 0:436a6a6b80a1 | 26 | while (true) { |
mfiore | 0:436a6a6b80a1 | 27 | printf("analog value: 0x%04X\r\n", in.read_u16()); |
mfiore | 0:436a6a6b80a1 | 28 | wait_ms(500); |
mfiore | 0:436a6a6b80a1 | 29 | } |
mfiore | 0:436a6a6b80a1 | 30 | } |