![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
main
Dependencies: Stepper mbed Ultrasonic PinDetect millis
Diff: main.cpp
- Revision:
- 6:6ca8a0ef7d4a
- Parent:
- 5:e958d61e0564
--- a/main.cpp Wed Dec 19 19:39:25 2018 +0000 +++ b/main.cpp Fri Jan 18 00:05:40 2019 +0000 @@ -3,12 +3,16 @@ #include "string" #include "hcsr04.h" #include "millis.h" +//#include "SDFileSystem.h" + Serial pc(USBTX, USBRX); -HCSR04 heightsensor(PTA2,PTC2); //(trig,echo) -HCSR04 pathsensor(PTD3,PTD2); +HCSR04 pathsensor(PTC2,PTA2); //(trig,echo) +HCSR04 heightsensor(PTD2,PTD3); DigitalOut in1(PTC12); DigitalOut in2(D7); -DigitalIn homeSwitch(D9); + +//DigitalIn homeSwitch(D9); +DigitalIn magnetSwitch(D10); Stepper mot(D3,D4); //(D3 to PUL+, D4 to DIR+) DigitalOut en(D2); @@ -20,13 +24,13 @@ { unsigned int dist; int er = 5; - int fp = 457; //adjust if needed + int fp = 447; //adjust if needed int lp = 64; //adjust if needed int tp = 25; wait(1); in1=1; in2=0; - wait_ms(600); + wait_ms(850); in1=1; in2=1; wait(1); @@ -130,8 +134,8 @@ { unsigned int path_dist; - int err = 11; - int sens_pos = 126; //adjust if needed //535 0 plates + int err = 12; + int sens_pos = 131; //adjust if needed //535 0 plates int sheet_th = 25; pathsensor.start(); wait_ms(500); @@ -210,11 +214,11 @@ void platedetect() { - if(homeSwitch==0 && path_sheets==0) + if(magnetSwitch==0 && path_sheets==0) { pc.printf("\nAll plates are in the start position"); } - else if (homeSwitch==1 && path_sheets==0) + else if (magnetSwitch==1 && path_sheets==0) { pc.printf("\nError-Plates are not fully extended"); } @@ -241,7 +245,7 @@ long Duration = 0; long StartTime = millis(); - while(homeSwitch == 1 && Duration <= 48000 ) + while(magnetSwitch == 1 && Duration <= 48000 ) { in1=0; in2=1; @@ -257,14 +261,14 @@ { in1=1; in2=0; - wait(48); + wait(56); in1=1; in2=1; } void internalpullups() { - homeSwitch.mode(PullUp); + magnetSwitch.mode(PullUp); wait (.01); } @@ -274,7 +278,7 @@ { pc.printf("\nERROR: Invalid Range |"); } - else if(homeSwitch == 1) + else if(magnetSwitch == 1) { pc.printf("\nERROR: Not at Home Position |"); } @@ -286,7 +290,7 @@ } void select_error_check() { - if (homeSwitch == 1) + if (magnetSwitch == 1) { pc.printf("\nERROR: Not at Home Position |"); } @@ -297,7 +301,7 @@ } void retract_error_check() { - if (homeSwitch == 0) + if (magnetSwitch == 0) { pc.printf("\nERROR: Already at Home Position |"); }