Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
Hi everyone, I have strange things happening here, is it because of the way the mbed works? I have two programs I use which totally fine independently when I combine them to function as one program it's like the mbed really slows down and the srf08 struggles..............here's the code I'm using
#include "mbed.h" #include "SRF08.h" #include "TextLCD.h" // For the Magnevation dual PWM module:- // Channel 1: p5 remains high on pin40 which is the brake pin to allow the motor to run. // When p6 is toggled between high/low motor direction is reversed. // Channel 2: p7 remains high on pin38 which is the brake pin to allow the motor to run. // When p8 is toggled between high/low motor direction is reversed. SRF08 srf08(p9, p10, 0xE0); // Define SDA, SCL pin and I2C address // TMP102 temperature(p9, p10, 0x90); Use later PwmOut MotorRightWheel(p23); // pwm PwmOut MotorLeftWheel(p25); // pwm DigitalOut DirectionR=p27; DigitalOut DirectionL=p29; DigitalOut BrakeR=p28; DigitalOut BrakeL=p30; // TMP102 temperature(p9, p10, 0x90); TextLCD lcd(p15, p16, p17, p18, p19, p20); float RangeReading() { float value; value = srf08.read(); return (value); } void DriveForwardFullSpeed() { for (float s= 0.0; s < 1.0 ; s += 0.01) { DirectionR=1;//Set the direction Right motor DirectionL=1;//Set the direction Left motor BrakeR = BrakeL = 0; MotorRightWheel=s; MotorLeftWheel=s; wait(0.2); } } void DriveForwardSlow() { for (float s= 1.0; s > 0.5 ; s -= 0.01) { DirectionR=1;//Set the direction Right motor DirectionL=1;//Set the direction Left motor BrakeR = BrakeL = 0; MotorRightWheel=s; MotorLeftWheel=s; wait(0.2); } } void DriveReverse() { for (float s= 0.0; s < 1.0 ; s += 0.01) { DirectionR=0;//Set the direction Right motor DirectionL=0;//Set the direction Left motor BrakeR = BrakeL = 0; MotorRightWheel=s; MotorLeftWheel=s; wait(0.2); } } void ZeroSpeedForward() { for (float s = 0.5; s > 0.0; s -= 0.01) { DirectionR=1;//Set the direction Right motor DirectionL=1;//Set the direction Left motor BrakeR = BrakeL = 0; MotorRightWheel=s; MotorLeftWheel=s; wait(0.2); } } void ZeroSpeedReverse() { for (float s = 1.0; s > 0.0; s -= 0.01) { DirectionR=0;//Set the direction Right motor DirectionL=0;//Set the direction Left motor BrakeR = BrakeL = 0; MotorRightWheel=s; MotorLeftWheel=s; wait(0.2); } } int main() { float distance; while (1) { lcd.cls(); distance = RangeReading(); lcd.printf("Range: %2.f cm\n",distance); // lcd.printf("Temp: %.2f degC\n", temperature.read()); if (distance >100) DriveForwardFullSpeed(); // else if (distance > 80 || distance < 100) // DriveForwardSlow(); // else if (distance < 50) // ZeroSpeedForward(); // wait(1); // DriveReverse(); // wait(1); // ZeroSpeedReverse(); // wait(5); } }