H BRIDGE PARA MOTORES DC KL64Z
Dependencies: Motor mbed Servo
Diff: main.cpp
- Revision:
- 2:d10dff926d9a
- Parent:
- 1:6ee374b19aaf
- Child:
- 3:858e483420a8
--- a/main.cpp Thu Jul 24 22:27:17 2014 +0000 +++ b/main.cpp Mon Jul 28 23:17:54 2014 +0000 @@ -4,27 +4,43 @@ Motor motor1(PTA1, PTA2, PTD3); // pwm, fwd, rev Motor motor2(PTA12,PTA4,PTA5); +AnalogIn sensorizq(PTB0); +AnalogIn sensorder(PTB2); +AnalogIn sensorcentro(PTB1); + +PwmOut anout(LED_RED),anout2(LED_GREEN); + + +float valorizq,valorder,valorcentro; int main() { while(1) { - for (float s= -1.0; s < 1.0 ; s += 0.01) { + /* for (float s= -1.0; s < 1.0 ; s += 0.01) { motor1.speed(s); motor2.speed(s); wait(0.02); } - for (float s= 1.0; s >-1.0 ; s -= 0.01) { + for (float s= 1.0; s >-1.0 ; s = s-0.01) { motor1.speed(s); motor2.speed(s); wait(0.02); } - motor1.speed(-0.2); - motor2.speed(-0.2); - wait(1.0); - motor1.speed(0.2); - motor2.speed(0.2); - wait(1.0); + + */ + valorder = 1.0-sensorder; + valorizq = 1.0-sensorizq; + valorcentro = 1.0-sensorcentro; + + motor1.speed(valorizq/10); + motor2.speed(valorder/10); + + + anout = valorizq/200; + anout2 = valorder/200; + // wait(3.0); + // printf("%u \r",sensorizq.read_u16()); } }