Test application for the library MCP23017_I2C
Dependencies: DebugLibrary MCP23017_I2C mbed
Diff: main.cpp
- Revision:
- 0:1d91b4046326
- Child:
- 1:e981573db063
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Jan 07 09:49:59 2015 +0000 @@ -0,0 +1,66 @@ +#include <string> +#include <iostream> +#include <iomanip> + +#include "MCP23017_I2C.h" + +/* + * Declare functions + */ +void AvailableIndicator(); // LED1 flashing for program while program is alive +DigitalOut g_availableLed(LED1); // To verify if program in running +Ticker g_available; // LED1 will flash with a period of 2s +char DisplayMenuAndGetChoice(); + +static CMCP23017_I2C g_gpioExp(p9, p10, 0x27, p15, p16, p17); + +int main() { + // Launch available indicator + g_available.attach(&AvailableIndicator, 2.0); + + g_gpioExp.Initialize(); + + while(true) { + switch (DisplayMenuAndGetChoice()) { + case 'a': + g_gpioExp.write(GPB0, 1); + break; + case 'b': + g_gpioExp.write(GPB0, 0); + break; + case 'c': + g_gpioExp.write(GPB2, 1); + break; + case 'd': + g_gpioExp.write(GPB2, 0); + break; + case 'r': + g_gpioExp.reset(); + break; + default: + std::cout << "Invalid user choice\r" << std::endl; + break; + } // End of 'switch' statement + + } // End of 'while' loop +} + +void AvailableIndicator() +{ + g_availableLed = !g_availableLed; +} // End of AvailableIndicator + +char DisplayMenuAndGetChoice() +{ + char value; + std::cout << "\r" << std::endl << "\r" << std::endl << "MCP23017_I2C v0.1\r" << std::endl; + std::cout << "\tSet PortB-0 :\t\ta\r" << std::endl; + std::cout << "\tUnset PortB-0 :\t\tb\r" << std::endl; + std::cout << "\tUnset PortB-2 :\t\tc\r" << std::endl; + std::cout << "\tUnset PortB-2 :\t\td\r" << std::endl; + std::cout << "\tReset device :\t\tr\r" << std::endl; + std::cout << "Enter your choice: " << std::flush; + value = getchar(); + std::cout << "\r" << std::endl; + return value; +}