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:
- 18:5a1c351094d2
- Parent:
- 15:a0b5c4306246
- Child:
- 19:0e9bf6d61d0d
--- a/main.cpp Wed Nov 16 00:21:32 2016 +0000 +++ b/main.cpp Wed Nov 16 02:10:43 2016 +0000 @@ -2,6 +2,7 @@ #include "Motor.h" #include "pot.h" #include <time.h> + Serial pc(USBTX, USBRX); //Use X4 encoding. @@ -23,7 +24,6 @@ wait_ms(200); int coast_pulses_cw = encoder.getPulses(); - encoder.reset(); motor.step_anticlockwise(steps, wait); int pulses_ccw = encoder.getPulses(); @@ -73,7 +73,7 @@ void calibrate_pendulum(){ encoder.reset(); while(1){ - printf("voltage %%: %f pulse: %i \r\n", pend.get_voltage(), encoder.getPulses()); + printf("voltage %%: %f pulse: %i", pend.get_voltage(), encoder.getPulses()); } } void move_pulses(int pulses){ // find number of pulses from the encoder going from one end to the other. @@ -87,8 +87,40 @@ motor.anticlockwise(); } } +void disttopulse(int distance) //find amount of pulses to distance +{ + +} +void set_speed(int speed) // wait time correspondence to speed +{ + +} + +void test_pulsetodist() // have user input x amount of pulses to move motor a certain distance +{ + while(1) + { + char str[4]; + int steps = 0; + int wait = 1000; + time_t start = time(0); + double elapsed; + printf("Enter the amount of steps: "); + fgets(str,4,stdin); + printf("\r\nSteps: %s", str); + steps = atoi(str); + + if(steps > 0) + motor.step_clockwise(steps, wait); + else + motor.step_anticlockwise(steps, wait); + elapsed = difftime( time(0), start); + printf("\r\nTook %i steps in time: %f \r\n",steps, elapsed); + } +} int main() { - calibrate_pendulum(); + while(1) + printf("Pulses: %i\r\n", encoder.getPulses()); //motor.step_clockwise(100,1500); //motor.step_clockwise(100,1000); //motor.step_clockwise(100,700);