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:
- 13:78a2481fd65b
- Parent:
- 12:75aab2bdb3a1
- Child:
- 14:a5fd98a957e6
--- a/main.cpp Tue Jun 05 14:21:47 2018 +0000 +++ b/main.cpp Wed Jun 06 11:44:35 2018 +0000 @@ -16,8 +16,11 @@ DigitalOut myled3(LED3); // DigitalOut myled4(LED4); // AnalogIn Ain(p20); // pot. met. +DigitalOut Track(p21); // train track -DigitalOut Track(p21); +AnalogIn detect_21(p15); // detectors pin d2, d21, d22 +AnalogIn detect_22(p16); +AnalogIn detect_2(p17); DigitalIn sw1(p5); // DigitalIn sw2(p30); // switches @@ -27,10 +30,15 @@ void mcpWriteReg(uint8_t address, uint8_t reg, uint8_t data); // Write an I2C register uint8_t mcpReadReg(uint8_t address, uint8_t reg); // Read an I2C register void initMcp0(void); +void readVoltage(); +void readDetector(); -unsigned int DarkRedtrain = 0x01; +unsigned int DCCaddress_darkRed = 0x01; +unsigned int DCCaddress_lightRed = 0x03; unsigned int DCCinst_forward = 0x68; //forward half speed +unsigned int DCCinst_forward_stop = 0x60; //forward and stop 01100000 + //move forward //speed dial @@ -50,15 +58,32 @@ int main() { while(1){ - unsigned int DCCaddress = 0x03; - DCC_send_command(DCCaddress,DCCinst_forward,400); // forward half speed train address 3 + //unsigned int DCCaddress = 0x03; + //unsigned int DCCaddress_darkRed = 0x01; + readDetector(); + lcd.printf("Forward"); + DCC_send_command(DCCaddress_lightRed,DCCinst_forward,400); // forward half speed train address 3 + wait(0.5); + lcd.printf("Stop"); + DCC_send_command(DCCaddress_lightRed,DCCinst_forward_stop,400); // forward half speed train address 3 + wait(1); + //readVoltage(); + //myled=1; + } +} + +void readDetector(){ + float val = detect_21.read(); + lcd.printf("%.2f", val); + } + +void readVoltage(){ float f = Ain.read(); //Read voltage value float Vin = f *3.3; lcd.printf("%.2f", Vin); + wait(0.1); lcd.printf("\n"); - //myled=1; } -} void mcpWriteReg(uint8_t address, uint8_t reg, uint8_t data){ char cmd[2];cmd[0] = reg;