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.
Diff: main.cpp
- Revision:
- 18:aa43bb62e60f
- Parent:
- 17:0a657e338356
- Child:
- 20:608ab9bf340d
--- a/main.cpp Thu Jun 07 12:20:12 2018 +0000 +++ b/main.cpp Thu Jun 07 12:35:18 2018 +0000 @@ -1,5 +1,8 @@ #include "mbed.h" #include "TextLCD.h" +#include "MCP23017.h" + + //mbed DCC Model Train Demo /******PINS AND DECLARATIONS*******/ @@ -11,9 +14,9 @@ //RAIL SENSORS - INT0,INT1 //INT0 - p9 -InterruptIn sensors0(p9); +InterruptIn int0(p9); //INT1 - p10 -InterruptIn sensors1(p10); +InterruptIn int1(p10); ///p11 ///p12 @@ -48,16 +51,37 @@ //LED2 - p30 DigitalOut greenled(p30); - -//Rail sensors -InterruptIn int0(p9); -InterruptIn int1(p10); +DigitalOut led1(LED1); +DigitalOut led2(LED2); +DigitalOut led3(LED3); //MCP MCP23017 *mcp; //**************** FUNCTIONS FOR DENVER TRAIN ****************// + + +void initialize_mcp(){ + mcp = new MCP23017(p28,p27,0x40); //Connect to SCL - p28 and SDA - p27 and MPC I2C address 0x40 + + mcp->reset(); + mcp->writeRegister(0x00, (unsigned char )0xff); + mcp->writeRegister(0x01, (unsigned char )0xff); + mcp->writeRegister(0x02, (unsigned char )0x00); + mcp->writeRegister(0x03, (unsigned char )0x00); + mcp->writeRegister(0x04, (unsigned char )0xff); + mcp->writeRegister(0x05, (unsigned char )0xff); + mcp->writeRegister(0x06, (unsigned char )0xff); + mcp->writeRegister(0x07, (unsigned char )0xff); + mcp->writeRegister(0x08, (unsigned char )0xff); + mcp->writeRegister(0x09, (unsigned char )0xff); + mcp->writeRegister(0x0a, (unsigned char )0x42); + mcp->writeRegister(0x0b, (unsigned char )0x42); + mcp->writeRegister(0x0c, (unsigned char )0x00); + mcp->writeRegister(0x0d, (unsigned char )0x00); +} + void interrupt0(){ int data = mcp->readRegister(GPIO); lcd.cls(); @@ -75,26 +99,6 @@ wait(0.5); buzz = 0; } - -void initalize_mcp(){ - mcp = new MPC23017(p28,p27,0x40); //Connect to SCL - p28 and SDA - p27 and MPC I2C address 0x40 - - mcp->reset(); - mcp->writeRegister(0x00, (unsigned char )0xff); - mcp->writeRegister(0x01, (unsigned char )0xff); - mcp->writeRegister(0x02, (unsigned char )0x00); - mcp->writeRegister(0x03, (unsigned char )0x00); - mcp->writeRegister(0x04, (unsigned char )0xff); - mcp->writeRegister(0x05, (unsigned char )0xff); - mcp->writeRegister(0x06, (unsigned char )0xff); - mcp->writeRegister(0x07, (unsigned char )0xff); - mcp->writeRegister(0x08, (unsigned char )0xff); - mcp->writeRegister(0x09, (unsigned char )0xff); - mcp->writeRegister(0x0a, (unsigned char )0x42); - mcp->writeRegister(0x0b, (unsigned char )0x42); - mcp->writeRegister(0x0c, (unsigned char )0x00); - mcp->writeRegister(0x0d, (unsigned char )0x00); -} void DCC_send_command(unsigned int address, unsigned int inst, unsigned int repeat_count) @@ -150,8 +154,8 @@ initialize_mcp(); - int0.rise($interrupt0); - int1.rise($interrupt1); + int0.rise(&interrupt0); + int1.rise(&interrupt1); //typical out of box default engine DCC address is 3 (at least for Bachmann trains)