Programming Advice

26 Mar 2011

So far I have working a srf08, a TMP102, a Magnevation dual motor driver board and an LCD display. I'd like some advice please on how to access the character data from the srf08. What I want to do is as the distance towards an object decreases I want to slow down the motors by modulating the pwm output then at a set value reverse the output. Can someone please offer some programming advice as to the best way of doing this? The next step for me is to add a compass module but I'm looking to have a some control of the motors first. Kind Regards Degs

26 Mar 2011

Just noticed that on the lcd display I'm using (which is a Powertip 1604A) The 16th character a capital C remains on the display is this because I have to clear the screen between cycles? Here's the code I'm using.

#include "mbed.h"
#include "SRF08.h"
#include "TMP102.h"
#include "TextLCD.h"

SRF08 srf08(p9, p10, 0xE0);      
TMP102 temperature(p9, p10, 0x90);
TextLCD lcd(p15, p16, p17, p18, p19, p20);

int main() {

    while (1) {
       lcd.printf("Range: %.2f cm\n",srf08.read());
       lcd.printf("Temp: %.2f degC\n", temperature.read());
       wait(5);
    }

}
26 Mar 2011

Loving this! Getting there following code is much clearer with the lcd.cls(); added Incidentally as with the srf08 I found the Powertip only started working at the higher voltage as 3.3v from the mbed was to low.

#include "mbed.h"
#include "SRF08.h"
#include "TMP102.h"
#include "TextLCD.h"

SRF08 srf08(p9, p10, 0xE0);      
TMP102 temperature(p9, p10, 0x90);
TextLCD lcd(p15, p16, p17, p18, p19, p20);

int main() {

    while (1) {
       lcd.cls();
       lcd.printf("Range: %.2f cm\n",srf08.read());
       lcd.printf("Temp: %.2f degC\n", temperature.read());
       wait(5);
    }

}
26 Mar 2011

Solved it by playing around as usual........to get the value from srf08 ............I can now use the float distance variable.

#include "mbed.h"
#include "SRF08.h"
#include "TMP102.h"
#include "TextLCD.h"

SRF08 srf08(p9, p10, 0xE0);      
TMP102 temperature(p9, p10, 0x90);
TextLCD lcd(p15, p16, p17, p18, p19, p20);

float RangeReading()
{float value;
value = srf08.read();
 return (value);} 

int main() {float distance;

    while (1) {lcd.cls();
       distance = RangeReading(); 
      // lcd.printf("Range: %.2f cm\n",srf08.read());
      lcd.printf("Range: %2.f cm\n",distance);
       lcd.printf("Temp: %.2f degC\n", temperature.read());
       wait(5);
    }

}