![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
TRR2018 omar
Fork of biniou by
Diff: main.cpp
- Revision:
- 1:abed67ad1d03
- Parent:
- 0:3d0394820179
- Child:
- 8:1d8c3ca5e508
--- a/main.cpp Wed Aug 22 16:12:16 2018 +0000 +++ b/main.cpp Wed Aug 22 16:15:52 2018 +0000 @@ -1,24 +1,108 @@ #include "mbed.h" - -AnalogIn analog_value(A0); - +AnalogIn front_G(PC_0); +AnalogIn front_C(PC_1); +AnalogIn front_D(PC_2); + +AnalogIn analog_left(A0); +AnalogIn analog_right(A1); +AnalogIn analog_front(A2); + +//DigitalOut enable_right(D0); +//DigitalOut forward_right(PA_10,0); +//DigitalOut backward_right(PA_9,0); + +//DigitalOut backward_left(PA_10,0); +//DigitalOut forward_left(PB_3,0); +//DigitalOut enable_left(D5); + +PwmOut pwm_right(PB_4); +PwmOut pwm_left(PB_5); + +int on_off = 0 ; +InterruptIn button(USER_BUTTON); + DigitalOut led(LED1); -int main() { - float meas; - - printf("\nAnalogIn example\n"); - - while(1) { - meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0) - meas = meas * 3300; // Change the value to be in the 0 to 3300 range - printf("measure = %.0f mV\n", meas); - if (meas > 2000) { // If the value is greater than 2V then switch the LED on - led = 1; - } - else { - led = 0; - } - wait(0.2); // 200 ms +void pressed() +{ + if (on_off == 0) { + on_off = 1 ; + } else { + on_off = 0; } } + +int main() +{ + float front_meas; + float left_meas; + float right_meas; + + button.fall(&pressed); + + pwm_right.period_us(500); + pwm_left.period_us(500); + pwm_right.pulsewidth_us(0); + pwm_left.pulsewidth_us(0); + + // backward_right.write(0);//ok + // forward_right.write(1);//ko + + // forward_left.write(1); //ok + // backward_left.write(0); //ok + + while(1) { + /* + if (on_off == 1 ) { + led = 1; + + front_meas = analog_front.read(); + left_meas = analog_left.read(); + right_meas = analog_right.read(); + + if (front_meas > 0.5) { + if (left_meas > right_meas) { + backward_right.write(0);//ok + forward_right.write(1);//ko + forward_left.write(0); //ok + backward_left.write(1); //ok + } else { + backward_right.write(1);//ok + forward_right.write(0);//ko + forward_left.write(1); //ok + backward_left.write(0); //ok + } + } else { + if(left_meas < 0.5) { + forward_left.write(1); //ok + backward_left.write(0); //ok + } else { + forward_left.write(0); //ok + backward_left.write(1); //ok + } + if(right_meas > 0.5) { + forward_right.write(0); //ok + backward_right.write(1); //ok + } else { + forward_right.write(1); //ok + backward_right.write(0); //ok + } + } + pwm_right.pulsewidth_us(200); + pwm_left.pulsewidth_us(200); + + + } else { + led = 0; + pwm_right.pulsewidth_us(0); + pwm_left.pulsewidth_us(0); + }*/ + wait(0.2); // 200 ms + + } +} + + + + +