Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp@2:292acfb6a3af, 2016-02-26 (annotated)
- Committer:
- mfiore
- Date:
- Fri Feb 26 16:52:18 2016 +0000
- Revision:
- 2:292acfb6a3af
- Parent:
- 1:5770646ab65b
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 | 1:5770646ab65b | 1 | /** Dragonfly DigitalIn and BusIn Example Program |
| mfiore | 0:c7d463ff3deb | 2 | * |
| mfiore | 0:c7d463ff3deb | 3 | * This program demonstrates how to read digital inputs using the |
| mfiore | 0:c7d463ff3deb | 4 | * MultiTech Dragonfly and MultiTech UDK2 hardware. The only |
| mfiore | 0:c7d463ff3deb | 5 | * additional hardware required is jumper wires. |
| mfiore | 0:c7d463ff3deb | 6 | * |
| mfiore | 0:c7d463ff3deb | 7 | * Pins are active low, so 0V = 0 and 5V/3.3V = 1. |
| mfiore | 0:c7d463ff3deb | 8 | * |
| mfiore | 0:c7d463ff3deb | 9 | * This program prints the new value of the BusIn each time it changes |
| mfiore | 0:c7d463ff3deb | 10 | * and the new value of the DigitalIn each time it changes. |
| mfiore | 0:c7d463ff3deb | 11 | */ |
| mfiore | 0:c7d463ff3deb | 12 | |
| mfiore | 0:c7d463ff3deb | 13 | #include "mbed.h" |
| mfiore | 2:292acfb6a3af | 14 | |
| mfiore | 2:292acfb6a3af | 15 | // This line controls the regulator's battery charger. |
| mfiore | 2:292acfb6a3af | 16 | // BC_NCE = 0 enables the battery charger |
| mfiore | 2:292acfb6a3af | 17 | // BC_NCE = 1 disables the battery charger |
| mfiore | 2:292acfb6a3af | 18 | DigitalOut bc_nce(PB_2); |
| mfiore | 0:c7d463ff3deb | 19 | |
| mfiore | 0:c7d463ff3deb | 20 | int main() { |
| mfiore | 2:292acfb6a3af | 21 | // Disable the battery charger unless a battery is attached. |
| mfiore | 2:292acfb6a3af | 22 | bc_nce = 1; |
| mfiore | 2:292acfb6a3af | 23 | |
| mfiore | 0:c7d463ff3deb | 24 | // read digital pins D9 and D10 as a 2 pin bus |
| mfiore | 0:c7d463ff3deb | 25 | // the first pin is the LSB of the bus, the last is the MSB |
| mfiore | 0:c7d463ff3deb | 26 | BusIn bus(D9, D10); |
| mfiore | 0:c7d463ff3deb | 27 | // read digital pin D12 |
| mfiore | 0:c7d463ff3deb | 28 | DigitalIn din(D12); |
| mfiore | 0:c7d463ff3deb | 29 | |
| mfiore | 0:c7d463ff3deb | 30 | int old_bus = -1; |
| mfiore | 0:c7d463ff3deb | 31 | int old_din = -1; |
| mfiore | 0:c7d463ff3deb | 32 | |
| mfiore | 0:c7d463ff3deb | 33 | while (true) { |
| mfiore | 0:c7d463ff3deb | 34 | if (bus != old_bus) { |
| mfiore | 0:c7d463ff3deb | 35 | old_bus = bus; |
| mfiore | 0:c7d463ff3deb | 36 | printf("bus = %d\r\n", old_bus); |
| mfiore | 0:c7d463ff3deb | 37 | } |
| mfiore | 0:c7d463ff3deb | 38 | if (din != old_din) { |
| mfiore | 0:c7d463ff3deb | 39 | old_din = din; |
| mfiore | 0:c7d463ff3deb | 40 | printf("din = %d\r\n", old_din); |
| mfiore | 0:c7d463ff3deb | 41 | } |
| mfiore | 0:c7d463ff3deb | 42 | |
| mfiore | 0:c7d463ff3deb | 43 | wait_ms(100); |
| mfiore | 0:c7d463ff3deb | 44 | } |
| mfiore | 0:c7d463ff3deb | 45 | } |