BERTL_CHEL18
/
Func_Bertl_Ultra
ultra sonic sensor asdded
Fork of func_Bertl by
main.cpp@1:f2d7bec926ce, 2015-01-02 (annotated)
- Committer:
- bulmecisco
- Date:
- Fri Jan 02 19:32:23 2015 +0000
- Revision:
- 1:f2d7bec926ce
- Parent:
- 0:0b7c22955b8c
- Child:
- 2:43547160ab56
ur_Karel with speed control
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Enenkel | 0:0b7c22955b8c | 1 | /*********************************** |
bulmecisco | 1:f2d7bec926ce | 2 | name: Karel |
bulmecisco | 1:f2d7bec926ce | 3 | author: PE HTL BULME |
bulmecisco | 1:f2d7bec926ce | 4 | email: pe@bulme.at |
Enenkel | 0:0b7c22955b8c | 5 | description: |
bulmecisco | 1:f2d7bec926ce | 6 | Funktionen von Karel The Robot |
Enenkel | 0:0b7c22955b8c | 7 | |
bulmecisco | 1:f2d7bec926ce | 8 | |
Enenkel | 0:0b7c22955b8c | 9 | ***********************************/ |
Enenkel | 0:0b7c22955b8c | 10 | #include "mbed.h" |
Enenkel | 0:0b7c22955b8c | 11 | |
bulmecisco | 1:f2d7bec926ce | 12 | void move() |
bulmecisco | 1:f2d7bec926ce | 13 | { |
bulmecisco | 1:f2d7bec926ce | 14 | DigitalOut MotorL_EN(p34); |
bulmecisco | 1:f2d7bec926ce | 15 | DigitalOut MotorL_FORWARD(P1_1); |
bulmecisco | 1:f2d7bec926ce | 16 | //DigitalOut MotorL_REVERSE(P1_0); |
bulmecisco | 1:f2d7bec926ce | 17 | |
bulmecisco | 1:f2d7bec926ce | 18 | DigitalOut MotorR_EN(p36); |
bulmecisco | 1:f2d7bec926ce | 19 | DigitalOut MotorR_FORWARD(P1_3); |
bulmecisco | 1:f2d7bec926ce | 20 | //DigitalOut MotorR_REVERSE(P1_4); |
bulmecisco | 1:f2d7bec926ce | 21 | |
bulmecisco | 1:f2d7bec926ce | 22 | MotorR_EN=MotorL_EN=1; // Beide Motoren ENABLE |
bulmecisco | 1:f2d7bec926ce | 23 | |
bulmecisco | 1:f2d7bec926ce | 24 | MotorR_FORWARD = MotorL_FORWARD = 1; // Beide Motoren vorwärts EIN |
bulmecisco | 1:f2d7bec926ce | 25 | wait_ms(250); // warte 0,25 Sekunde |
bulmecisco | 1:f2d7bec926ce | 26 | MotorR_FORWARD = MotorL_FORWARD = 0; // Motoren AUS |
bulmecisco | 1:f2d7bec926ce | 27 | //wait_ms(250); |
bulmecisco | 1:f2d7bec926ce | 28 | } |
bulmecisco | 1:f2d7bec926ce | 29 | |
bulmecisco | 1:f2d7bec926ce | 30 | void moveSpeed(float speedy) |
bulmecisco | 1:f2d7bec926ce | 31 | { |
bulmecisco | 1:f2d7bec926ce | 32 | DigitalOut MotorL_EN(p34); |
bulmecisco | 1:f2d7bec926ce | 33 | DigitalOut MotorL_FORWARD(P1_1); |
bulmecisco | 1:f2d7bec926ce | 34 | //DigitalOut MotorL_REVERSE(P1_0); |
Enenkel | 0:0b7c22955b8c | 35 | |
bulmecisco | 1:f2d7bec926ce | 36 | DigitalOut MotorR_EN(p36); |
bulmecisco | 1:f2d7bec926ce | 37 | DigitalOut MotorR_FORWARD(P1_3); |
bulmecisco | 1:f2d7bec926ce | 38 | //DigitalOut MotorR_REVERSE(P1_4); |
bulmecisco | 1:f2d7bec926ce | 39 | PwmOut mg1(p34); //PWM Ausgang zum Motor |
bulmecisco | 1:f2d7bec926ce | 40 | PwmOut mg2(p36); |
bulmecisco | 1:f2d7bec926ce | 41 | mg1=mg2=speedy; |
bulmecisco | 1:f2d7bec926ce | 42 | |
bulmecisco | 1:f2d7bec926ce | 43 | MotorR_EN=MotorL_EN=1; // Beide Motoren ENABLE |
bulmecisco | 1:f2d7bec926ce | 44 | |
bulmecisco | 1:f2d7bec926ce | 45 | MotorR_FORWARD = MotorL_FORWARD = 1; // Beide Motoren vorwärts EIN |
bulmecisco | 1:f2d7bec926ce | 46 | wait_ms(2000); // warte 0,25 Sekunde |
bulmecisco | 1:f2d7bec926ce | 47 | MotorR_FORWARD = MotorL_FORWARD = 0; // Motoren AUS |
bulmecisco | 1:f2d7bec926ce | 48 | MotorR_EN=MotorL_EN=0; // Beide Motoren ENABLE |
bulmecisco | 1:f2d7bec926ce | 49 | wait_ms(500); |
bulmecisco | 1:f2d7bec926ce | 50 | } |
bulmecisco | 1:f2d7bec926ce | 51 | void move(int anzahl) |
bulmecisco | 1:f2d7bec926ce | 52 | { |
bulmecisco | 1:f2d7bec926ce | 53 | |
bulmecisco | 1:f2d7bec926ce | 54 | for(int i=0; i < anzahl; i++) |
bulmecisco | 1:f2d7bec926ce | 55 | move(); |
bulmecisco | 1:f2d7bec926ce | 56 | |
bulmecisco | 1:f2d7bec926ce | 57 | } |
bulmecisco | 1:f2d7bec926ce | 58 | |
bulmecisco | 1:f2d7bec926ce | 59 | void turnLeft() |
bulmecisco | 1:f2d7bec926ce | 60 | { |
bulmecisco | 1:f2d7bec926ce | 61 | // DigitalOut MotorL_EN(p34); |
bulmecisco | 1:f2d7bec926ce | 62 | // DigitalOut MotorL_FORWARD(P1_1); |
bulmecisco | 1:f2d7bec926ce | 63 | // DigitalOut MotorL_REVERSE(P1_0); |
bulmecisco | 1:f2d7bec926ce | 64 | |
bulmecisco | 1:f2d7bec926ce | 65 | DigitalOut MotorR_EN(p36); |
bulmecisco | 1:f2d7bec926ce | 66 | DigitalOut MotorR_FORWARD(P1_3); |
bulmecisco | 1:f2d7bec926ce | 67 | // DigitalOut MotorR_REVERSE(P1_4); |
bulmecisco | 1:f2d7bec926ce | 68 | // MotorL_EN=1; |
bulmecisco | 1:f2d7bec926ce | 69 | |
bulmecisco | 1:f2d7bec926ce | 70 | MotorR_EN=1; // rechten Motor ENABLE |
bulmecisco | 1:f2d7bec926ce | 71 | |
bulmecisco | 1:f2d7bec926ce | 72 | MotorR_FORWARD = 1; // rechter Motor vorwärts EIN |
bulmecisco | 1:f2d7bec926ce | 73 | wait_ms(750); // warte (90°) |
bulmecisco | 1:f2d7bec926ce | 74 | MotorR_FORWARD = 0; // Motoren AUS |
bulmecisco | 1:f2d7bec926ce | 75 | } |
Enenkel | 0:0b7c22955b8c | 76 | |
Enenkel | 0:0b7c22955b8c | 77 | // ************* Hauptprogramm ************ |
bulmecisco | 1:f2d7bec926ce | 78 | int main() |
bulmecisco | 1:f2d7bec926ce | 79 | { |
bulmecisco | 1:f2d7bec926ce | 80 | //move(); |
bulmecisco | 1:f2d7bec926ce | 81 | //turnLeft(); |
bulmecisco | 1:f2d7bec926ce | 82 | DigitalOut LED_D10(P1_8); // LED D10 und D13 definieren |
bulmecisco | 1:f2d7bec926ce | 83 | DigitalOut LED_D11(P1_9); // LED D10 und D13 definieren |
bulmecisco | 1:f2d7bec926ce | 84 | DigitalOut LED_D12(P1_10); // LED D10 und D13 definieren |
bulmecisco | 1:f2d7bec926ce | 85 | DigitalOut LED_D13(P1_11); // |
Enenkel | 0:0b7c22955b8c | 86 | |
bulmecisco | 1:f2d7bec926ce | 87 | moveSpeed(0.25); |
bulmecisco | 1:f2d7bec926ce | 88 | LED_D10 = 1; |
bulmecisco | 1:f2d7bec926ce | 89 | moveSpeed(0.3); |
bulmecisco | 1:f2d7bec926ce | 90 | LED_D11 = 1; |
bulmecisco | 1:f2d7bec926ce | 91 | moveSpeed(0.4); |
bulmecisco | 1:f2d7bec926ce | 92 | LED_D12 = 1; |
bulmecisco | 1:f2d7bec926ce | 93 | moveSpeed(0.5); |
bulmecisco | 1:f2d7bec926ce | 94 | LED_D13 = 1; |
bulmecisco | 1:f2d7bec926ce | 95 | moveSpeed(0.6); |
bulmecisco | 1:f2d7bec926ce | 96 | LED_D10 = LED_D11 = LED_D12 = LED_D13 = 0; |
bulmecisco | 1:f2d7bec926ce | 97 | moveSpeed(0.7); |
bulmecisco | 1:f2d7bec926ce | 98 | LED_D10 = 1; |
bulmecisco | 1:f2d7bec926ce | 99 | moveSpeed(0.8); |
bulmecisco | 1:f2d7bec926ce | 100 | LED_D11 = 1; |
bulmecisco | 1:f2d7bec926ce | 101 | moveSpeed(0.9); |
bulmecisco | 1:f2d7bec926ce | 102 | LED_D12 = 1; |
bulmecisco | 1:f2d7bec926ce | 103 | moveSpeed(1.0); |
bulmecisco | 1:f2d7bec926ce | 104 | LED_D10 = LED_D11 = LED_D12 = LED_D13 = 1; |
bulmecisco | 1:f2d7bec926ce | 105 | //wait(2); |
bulmecisco | 1:f2d7bec926ce | 106 | //turnLeft(); |
bulmecisco | 1:f2d7bec926ce | 107 | //move(); |
bulmecisco | 1:f2d7bec926ce | 108 | //turnLeft(); |
bulmecisco | 1:f2d7bec926ce | 109 | //move(5); |
bulmecisco | 1:f2d7bec926ce | 110 | |
bulmecisco | 1:f2d7bec926ce | 111 | //wait(2); |
bulmecisco | 1:f2d7bec926ce | 112 | return 0; |
bulmecisco | 1:f2d7bec926ce | 113 | } |