Elevator
/
Elevator
The first code
main.cpp
- Committer:
- m172886
- Date:
- 2015-02-12
- Revision:
- 4:059832a0c7b9
- Parent:
- 3:7b0316e7cabc
- Child:
- 5:47d6ae63a1a3
File content as of revision 4:059832a0c7b9:
#include "mbed.h" #include "time.h" #include "Motor.h" AnalogIn ain(p17); Serial pc(USBTX, USBRX); Timer t; Motor m(p25,p27,p28); float error = Desired_distance - height; float height; float Lower_distance = 7; // lower floor in inches. float Upper_distance = 26; // upper floor in inches float Desired_distance = Lower_distance; // start low int main(void) { t.reset(); //reset timer to zero t.start(); //start timer data timestamp m.speed(0.0); while(1) { height = 193.125176919012*(pow(ain.read(),3))-353.927724612106*(pow(ain.read(),2))+218.749286479109*(ain.read())-23.2532105680997; pc.baud(9600); pc.format(7,SerialBase::None,1); pc.printf("%f,",height); pc.printf("%f,",ain.read()); //this prints the voltage pc.printf("%f",t.read()); pc.printf("\n"); if (error > 0) { m.speed(0.5); } else(error<0) { m.speed(-0.5) } } }