![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
TRR2018 omar
Fork of biniou by
main.cpp
- Committer:
- ohlimi2
- Date:
- 2018-08-22
- Revision:
- 1:abed67ad1d03
- Parent:
- 0:3d0394820179
- Child:
- 8:1d8c3ca5e508
File content as of revision 1:abed67ad1d03:
#include "mbed.h" 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); 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 } }