![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
150_robot_H_Bridge8835_DIR_PWM_US_Follow
main.cpp@0:68a3b91ee2a4, 2022-02-23 (annotated)
- Committer:
- itbusch
- Date:
- Wed Feb 23 18:55:12 2022 +0000
- Revision:
- 0:68a3b91ee2a4
150_robot_H_Bridge8835_DIR_PWM_US_Follow
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
itbusch | 0:68a3b91ee2a4 | 1 | /* mbed BuschA */ |
itbusch | 0:68a3b91ee2a4 | 2 | #include "mbed.h" |
itbusch | 0:68a3b91ee2a4 | 3 | #include "HCSR04.h" //US-Sensor Abstand |
itbusch | 0:68a3b91ee2a4 | 4 | #include "UP_US_Sensor.h" |
itbusch | 0:68a3b91ee2a4 | 5 | |
itbusch | 0:68a3b91ee2a4 | 6 | lcd mylcd; |
itbusch | 0:68a3b91ee2a4 | 7 | HCSR04 sonar(D2, D4); //Echo, Trigger Pin |
itbusch | 0:68a3b91ee2a4 | 8 | DigitalIn CableSwitch(D2); //PullUp auf Board, PA_10 |
itbusch | 0:68a3b91ee2a4 | 9 | PwmOut M1_PWM(D9); |
itbusch | 0:68a3b91ee2a4 | 10 | DigitalOut M1_DIR(D7); |
itbusch | 0:68a3b91ee2a4 | 11 | |
itbusch | 0:68a3b91ee2a4 | 12 | int main() |
itbusch | 0:68a3b91ee2a4 | 13 | { |
itbusch | 0:68a3b91ee2a4 | 14 | M1_PWM.period_ms(10); // PWM-Periode |
itbusch | 0:68a3b91ee2a4 | 15 | M1_DIR = 1; // Vorwärts... |
itbusch | 0:68a3b91ee2a4 | 16 | M1_PWM = 0.8; //Start-Speed |
itbusch | 0:68a3b91ee2a4 | 17 | float Abstand; |
itbusch | 0:68a3b91ee2a4 | 18 | while (1) |
itbusch | 0:68a3b91ee2a4 | 19 | { |
itbusch | 0:68a3b91ee2a4 | 20 | |
itbusch | 0:68a3b91ee2a4 | 21 | Abstandsmessung(); //Abstand in cm |
itbusch | 0:68a3b91ee2a4 | 22 | |
itbusch | 0:68a3b91ee2a4 | 23 | switch (Abstand) |
itbusch | 0:68a3b91ee2a4 | 24 | { |
itbusch | 0:68a3b91ee2a4 | 25 | case 50: M1_PWM = 0.1; break; |
itbusch | 0:68a3b91ee2a4 | 26 | case 100: M1_PWM = 0.3; break; |
itbusch | 0:68a3b91ee2a4 | 27 | case 150: M1_PWM = 0.5; break; |
itbusch | 0:68a3b91ee2a4 | 28 | case 200: M1_PWM = 0.7; break; |
itbusch | 0:68a3b91ee2a4 | 29 | case 250: M1_PWM = 0.9; break; |
itbusch | 0:68a3b91ee2a4 | 30 | case 300: M1_PWM = 1.0; break; |
itbusch | 0:68a3b91ee2a4 | 31 | } |
itbusch | 0:68a3b91ee2a4 | 32 | |
itbusch | 0:68a3b91ee2a4 | 33 | } |
itbusch | 0:68a3b91ee2a4 | 34 | thread_sleep_for(200); //Sleep = Warten... |
itbusch | 0:68a3b91ee2a4 | 35 | } |