Read a BusIn and a DigitalIn using the MultiTech mDot.

Dependencies:   mbed

Fork of Dragonfly_DigitalIn_BusIn_Example by MultiTech

Committer:
mfiore
Date:
Fri Oct 02 17:09:01 2015 +0000
Revision:
2:cecc69d42fc6
Parent:
1:5770646ab65b
update for mDot

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mfiore 2:cecc69d42fc6 1 /** mDot DigitalIn and BusIn Example Program
mfiore 0:c7d463ff3deb 2 *
mfiore 0:c7d463ff3deb 3 * This program demonstrates how to read digital inputs using the
mfiore 2:cecc69d42fc6 4 * MultiTech mDot 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 2:cecc69d42fc6 16 // read digital pins PA_4 and PA_6 (UDK2 pins D10 and D12) as a 2 pin bus
mfiore 0:c7d463ff3deb 17 // the first pin is the LSB of the bus, the last is the MSB
mfiore 2:cecc69d42fc6 18 BusIn bus(PA_4, PA_6);
mfiore 2:cecc69d42fc6 19 // read digital pin PA_5 (UDK2 pin D13)
mfiore 2:cecc69d42fc6 20 DigitalIn din(PA_5);
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 }