MultiTech / Mbed 2 deprecated Dragonfly_DigitalIn_BusIn_Example

Dependencies:   mbed

Committer:
mfiore
Date:
Thu Oct 01 20:21:44 2015 +0000
Revision:
0:c7d463ff3deb
Child:
1:5770646ab65b
initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mfiore 0:c7d463ff3deb 1 /** Dragonfly DigitalIn, BusIn, and InterruptIn 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 0:c7d463ff3deb 14
mfiore 0:c7d463ff3deb 15 int main() {
mfiore 0:c7d463ff3deb 16 // read digital pins D9 and D10 as a 2 pin bus
mfiore 0:c7d463ff3deb 17 // the first pin is the LSB of the bus, the last is the MSB
mfiore 0:c7d463ff3deb 18 BusIn bus(D9, D10);
mfiore 0:c7d463ff3deb 19 // read digital pin D12
mfiore 0:c7d463ff3deb 20 DigitalIn din(D12);
mfiore 0:c7d463ff3deb 21
mfiore 0:c7d463ff3deb 22 int old_bus = -1;
mfiore 0:c7d463ff3deb 23 int old_din = -1;
mfiore 0:c7d463ff3deb 24
mfiore 0:c7d463ff3deb 25 while (true) {
mfiore 0:c7d463ff3deb 26 if (bus != old_bus) {
mfiore 0:c7d463ff3deb 27 old_bus = bus;
mfiore 0:c7d463ff3deb 28 printf("bus = %d\r\n", old_bus);
mfiore 0:c7d463ff3deb 29 }
mfiore 0:c7d463ff3deb 30 if (din != old_din) {
mfiore 0:c7d463ff3deb 31 old_din = din;
mfiore 0:c7d463ff3deb 32 printf("din = %d\r\n", old_din);
mfiore 0:c7d463ff3deb 33 }
mfiore 0:c7d463ff3deb 34
mfiore 0:c7d463ff3deb 35 wait_ms(100);
mfiore 0:c7d463ff3deb 36 }
mfiore 0:c7d463ff3deb 37 }