speed increment for loop
Dependencies: Encoder HIDScope MODSERIAL mbed
Diff: main.cpp
- Revision:
- 2:c8a030f3b4e7
- Parent:
- 1:e0c4625bbbab
- Child:
- 3:e333b4258af4
--- a/main.cpp Sun Sep 20 16:31:03 2015 +0000 +++ b/main.cpp Wed Sep 23 09:10:48 2015 +0000 @@ -1,26 +1,35 @@ #include "mbed.h" #include "encoder.h" +#include "MODSERIAL.h" - -Encoder encoder1(D13,D12); -DigitalOut motor2direction(D4); //D4 en D5 zijn motor 2 (op het motorshield) -PwmOut motor2speed(D5); - - -int main() -{ - int position = encoder1.getPosition(); - Serial pc(USBTX,USBRX); + +int main(){ + //VARIABLES + AnalogIn potmeter(A1); + AnalogIn potmeter2(A0); + DigitalIn button(D8); + MODSERIAL pc(USBTX,USBRX); + + Encoder motor1(D13,D12,true); // channel A and B from encoder, true - getSpeed works + PwmOut pwm_motor1(D6); // D4 and D5 = motor 2, D7 and D6 = motor 2 + DigitalOut dir_motor1(D7); // + + Encoder motor2(D10,D9,true); // channel A and B from encoder, true - getSpeed works + PwmOut pwm_motor2(D5); // D4 and D5 = motor 2, D7 and D6 = motor 2 + DigitalOut dir_motor2(D4); // + + //CODE pc.baud(9600); - motor2speed=0.0f; - motor2direction=1; - + + + while (1) { - if(stop_knop.read() == 0) { - motor2speed=0.0f; - } - while (true) { - - pc.printf("pos: %d, speed %f \r\n",encoder1.getPosition(), encoder1.getSpeed()); + pwm_motor2.period(0.0001); + for (float s= 0.0f; s <= 1.1f ; s += 0.01f) { + dir_motor2=1; + pwm_motor2.write(s); + wait(0.1); + pc.printf("pwm duty: %f, %d, \n\r", s, motor2.getPosition()); + } } } \ No newline at end of file