Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of bertl14 by
Diff: bertl14.cpp
- Revision:
- 0:f40ab7184c3f
- Child:
- 1:01bc0c86f111
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bertl14.cpp Mon Jan 18 09:44:28 2016 +0000 @@ -0,0 +1,57 @@ +#include <mbed.h> +#include "bertl14.h" + +DigitalOut engineLR(P1_0); //IN1, EP10, MG1A => MG1 engine-Pin 2, left_Reverse +DigitalOut engineLF(P1_1); //IN2, EP11, MG1B => MG1 engine-Pin 1, left_Forward +PwmOut engineLEN(p34); //EN1, P34, left_ENABLE +DigitalOut engineRR(P1_4); //IN4, EP13, MG2A => MG2 engine-Pin 2, right_Reverse +DigitalOut engineRF(P1_3); //IN3, EP14, MG2B => MG2 engine-Pin 1, right_Forward +PwmOut engineREN(p36); //EN2, P36, right_ENABLE + +void bertl_engine(int left, int right) +{ + // If the left engines-value is greater than 0, the left engine turn FORWARD + if(left > 0) + { + engineLF=1; + engineLR=0; + } + // Or if the left engines-value is less than 0, the left engine turn REVERSE + else if(left < 0) + { + engineLF=0; + engineLR=1; + left = left * (-1); // For PWM the Value have to be positive + } + // If the right engines-value is greater than 0, the right engine turn FORWARD + if(right > 0) + { + engineRF=1; + engineRR=0; + } + // Or if the right engines-value is less than 0, the right engine turn REVERSE + else if(right < 0) + { + engineRF=0; + engineRR=1; + right = right * (-1); // For PWM the Value have to be positive + } + //pc.printf("left: %4d\r\n", left); + //pc.printf("right: %4d\r\n", right); + // Or if the right- or/and the left engines value equals 0, the ENABLE-Pin turn off (ENABLE Pin equals 0) + engineLEN=(left/255.0); // PWM Value : 0 ... 1 + engineREN=(right/255.0); // PWM Value : 0 ... 1 +} +//Begin Testing bertl-engines +void bertl_engine_test() +{ + bertl_engine(100, 0); //The left engine must turn FORWARD for 2 seconds + wait(2); + bertl_engine(0, 100); //The right engine must turn FORWARD for 2 seconds + wait(2); + bertl_engine(-100, 0); //The left engine must turn REVERSE for 2 seconds + wait(2); + bertl_engine(0, -100); //The right engine must turn REVERSE for 2 seconds + wait(2); +} +//End Testing bertl-engines \ No newline at end of file