- include "mbed.h"
- include "HMC6352.h"
- include "SRF08.h"
- include "TextLCD.h"
This program uses the Magnevation Dual Driver board that I originally
had for the OOPIC. I have the board driving HN-GH12-2217Y geared motors
type HSIANG NENG.
HMC6352 compass(p9, p10);
SRF08 srf08(p28, p29,0xE0);   Define SDA, SCL pin and I2C address
PwmOut MotorRightWheel(p21);  pwm was p23
PwmOut MotorLeftWheel(p22);   pwm was p25
DigitalOut DirectionR=p23;Sets the direction pin on the Magnevation was p27
DigitalOut DirectionL=p24; was p29
DigitalOut BrakeR=p25;Releases the Brake pin on the Magnevation was p28
DigitalOut BrakeL=p26; was p30
TextLCD lcd(p15, p16, p17, p18, p19, p20);
float RangeReading() {
    float value;
    value = srf08.read();
    return (value);
}
float DriveForwardFullSpeed() {
    float s;
    DirectionR=0;Set the direction Right motor
    DirectionL=1;Set the direction Left motor
    BrakeR = BrakeL = 1;Take Brake OFF
    for (s= 0.0; s < 1.0 ; s += 0.01) {
        MotorRightWheel=s;
        MotorLeftWheel=s;
        wait(0.2);
    }
    return (s);
}
float DriveReverse() {
    float s =0;
    DirectionR=1;Set the direction Right motor
    DirectionL=0;Set the direction Left motor
    BrakeR = BrakeL = 1; Take Brake OFF
    for (float s= 0.0; s < 1.0 ; s += 0.01) {
        MotorRightWheel=s;
        MotorLeftWheel=s;
        wait(0.2);
    }
    wait(0.2); Slow down and stop
    for (float s = 1.0; s > 0.0; s -= 0.01) {
        MotorRightWheel=s;
        MotorLeftWheel=s;
        wait(0.2);
    }
    BrakeR = BrakeL = 0; Put Brake ON
    return (s);
}
float ZeroSpeedForward() {
    float s =0;
    DirectionR=0;Set the direction Right motor
    DirectionL=1;Set the direction Left motor
    for (float s = 1.0; s > 0.0; s -= 0.01) {
        MotorRightWheel=s;
        MotorLeftWheel=s;
        wait(0.2);
    }
    BrakeR = BrakeL = 0; Put Brake ON
    return (s);
}
int main() {
    lcd.printf("Starting HMC6352 test...\n");
    Continuous mode, periodic set/reset, 20Hz measurement rate.
    compass.setOpMode(HMC6352_CONTINUOUS, 1, 20);
    float distance, speed = 0;
    while (1) {
        wait(0.1);
        lcd.cls();
        lcd.printf("Heading is: %f\n", compass.sample() / 10.0);
        wait(1.0);
        distance = RangeReading();
        lcd.printf("\nRange: %2.f cm\n",distance);
        wait(0.2);
        if (distance >100  && speed <0.1) {
            lcd.printf("Forward \n");
            speed = DriveForwardFullSpeed();
        }
        distance = RangeReading();
        lcd.printf("Range: %2.f cm\n",distance);
        if  (distance < 100 && speed >0.5) {
            speed = ZeroSpeedForward();
        }
        distance = RangeReading();
        if (distance > 0.0 && speed == 0.0) {
            lcd.printf("Reverse \n");
            speed = DriveReverse();
        }
        wait (0.5);
    }
}
                    
                 
                
            
Hi All, I've put together a program using the HMC6352_Hello World, SRF08 and TextLCD as part of my main Roaming program.
If I just use the HMRC6352 and TextLCD it compiles fine no errors and I can download to the mbed and run it and see the compass heading displayed on the lcd screen - so all ok.
Putting it all together I get the following compiler error -
No valid source files to compile?
Any ideas please. Thank you Degs