![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
150_robot_H_Bridge8835_DIR_PWM_US_Follow
main.cpp
- Committer:
- itbusch
- Date:
- 2022-02-23
- Revision:
- 0:68a3b91ee2a4
File content as of revision 0:68a3b91ee2a4:
/* mbed BuschA */ #include "mbed.h" #include "HCSR04.h" //US-Sensor Abstand #include "UP_US_Sensor.h" lcd mylcd; HCSR04 sonar(D2, D4); //Echo, Trigger Pin DigitalIn CableSwitch(D2); //PullUp auf Board, PA_10 PwmOut M1_PWM(D9); DigitalOut M1_DIR(D7); int main() { M1_PWM.period_ms(10); // PWM-Periode M1_DIR = 1; // Vorwärts... M1_PWM = 0.8; //Start-Speed float Abstand; while (1) { Abstandsmessung(); //Abstand in cm switch (Abstand) { case 50: M1_PWM = 0.1; break; case 100: M1_PWM = 0.3; break; case 150: M1_PWM = 0.5; break; case 200: M1_PWM = 0.7; break; case 250: M1_PWM = 0.9; break; case 300: M1_PWM = 1.0; break; } } thread_sleep_for(200); //Sleep = Warten... }