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:
- 69:609c69e91b4e
- Parent:
- 68:9859a3ff9298
- Child:
- 70:594fe5c1ad5c
--- a/main.cpp Tue Jun 26 14:22:47 2018 +0000 +++ b/main.cpp Wed Jun 27 09:20:28 2018 +0000 @@ -68,6 +68,7 @@ DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); +DigitalOut led4(LED4); //MCP MCP23017 *mcp; @@ -455,7 +456,7 @@ //possibility of an array having {dr_train, lr_train}? for reuse and modularity of functions - +int speedcheck = 0; //****** SYSTEM LOGGER FUNCTIONS ******// @@ -1326,24 +1327,35 @@ if(switch1 == 1){ - lcd.cls(); - lcd.printf("Switch 1 ON - SW1"); - flip_switch(1,5); + //lcd.cls(); + //lcd.printf("TRAIN NOW WILL STOP AT STATION"); }else if(switch2 == 1){ - lcd.cls(); - lcd.printf("Switch 2 ON - SW2"); - flip_switch(2,5); - }else if(switch3 == 0){ + //lcd.cls(); + //lcd.printf("SPEEDCHECKMODE"); + //change to speedcheckmode + speedcheck = 1; + }else{ + + //lcd.cls(); + //lcd.printf("NORMAL MODE"); + speedcheck = 0; + }if(switch3 == 0){ - lcd.cls(); - lcd.printf("Switch 3 ON - SW3"); - flip_switch(3,5); + if(speedcheck>0){ + + //lcd.cls(); + //lcd.printf("SPEED TRAIN DARK RED"); + speedcheck = 2; + } }else if(switch4 == 0){ - - lcd.cls(); - lcd.printf("Switch 4 ON - IDLE"); - flip_switch(0,5); + + if(speedcheck>0){ + + //lcd.cls(); + //lcd.printf("SPEED TRAIN LIGHT RED"); + speedcheck = 3; + } } } @@ -1389,6 +1401,7 @@ return sensor; } + /** * Returns a boolean representing the direction. Everytimew switch3 is 0 it changes the direction. * When switch4 is 0 the selection is confirmed. @@ -1440,6 +1453,51 @@ return going_cw; } + +/** +* +* +* +**/ +void adjustSpeed(Train* train){ + + float f = pot.read(); + float vin = f * 3.3; + lcd.cls(); + // lcd.printf("vin: %.4f",vin); + + if(0<=vin && vin<0.60){ + + //speed = slow + train->set_speed(SLOW); + }else if(0.60<vin && vin<1.20){ + + //speed medium + train->set_speed(MEDIUM); + }else if(1.20<vin && vin<2.20){ + + //speed fast + train->set_speed(FAST); + }else if(2.20<vin && vin<3.20){ + + //speed full + train->set_speed(FULL); + } +} + +void switch_toSpeed(){ + + switch(speedcheck){ + + case 2: + adjustSpeed(&DR_train); + + case 3: + adjustSpeed(&LR_train); + + } +} + //**************** MAIN PROGRAM FOR DENVER TRAIN ****************// @@ -1547,7 +1605,10 @@ //Demo for stopping at the station while(1) { + checkSwitch(); //Checks for switch commands everytime. + switch_toSpeed(); + lcd.cls(); check_position(); if(1==0){