Elevator
/
Elevator
The first code
Revision 6:922f762e7f92, committed 2015-02-19
- Comitter:
- m172886
- Date:
- Thu Feb 19 15:46:03 2015 +0000
- Parent:
- 5:47d6ae63a1a3
- Child:
- 7:987db6b7e1b8
- Commit message:
- Final logic code
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Feb 14 02:30:41 2015 +0000 +++ b/main.cpp Thu Feb 19 15:46:03 2015 +0000 @@ -9,14 +9,14 @@ float height; -float Lower_distance = 7; // lower floor in inches. +float Lower_distance = 10; // lower floor in inches. -float Upper_distance = 22; // upper floor in inches +float Upper_distance = 20; // upper floor in inches -float Desired_distance = Upper_distance; // start low +float Desired_distance = Lower_distance; // start low float err; -int time_count = 0; +int time_count; int main() { @@ -26,8 +26,11 @@ t.start(); //start timer data timestamp while(1) { + time_count = 0; while(time_count<300) { + + height = 193.125176919012*(pow(ain.read(),3))-353.927724612106*(pow(ain.read(),2))+218.749286479109*(ain.read())-23.2532105680997; @@ -37,32 +40,32 @@ pc.printf("%f",t.read()); pc.printf("\n\r"); - if(height < Desired_distance) { - + err = Desired_distance-height; + if(err>0) { + m.speed(0.7); - } else if(height > Desired_distance) { - + } else if(err<0) { + m.speed(-0.7); - } else if(height==Desired_distance) { - - m.speed(0.0); + } - time_count = time_count+1; + time_count=time_count+1; + + + + + } - if (height == Desired_distance) - { + if(Desired_distance==Lower_distance) { + Desired_distance = Upper_distance; + } + else if(Desired_distance==Upper_distance) { Desired_distance = Lower_distance; - if(height < Desired_distance) { - - m.speed(0.7); - } else if(height > Desired_distance) { - - m.speed(-0.7); - } else if(height==Desired_distance) { - - m.speed(0.0); - } } + + } + + } \ No newline at end of file