Hello again,
I had the following code working. I added a simple pwm to test a motor controller. I somehow killed my mbed and had to replace it. After getting the new mbed, I added more to my code because I thought it was working. I now cant get it to parse and change the pwm value or printf anything. I tested the simple srial demos and they work just fine. I reduced my code to just a simple scanf-printf program and cant get it to work.
#include "mbed.h"
int main()
{
// Set the Serial variables
Serial pc(USBTX, USBRX); // USBTX - Tranmit on USB USBRX - receive on USB
pc.baud(9600);
pc.format(8, Serial::None, 1);
// Serial xbee(p9, p10); // tx, rx
// xbee.baud(9600);
// xbee.format(8, Serial::None, 1);
pc.printf("I'm alive!");
//variables
float mtrl, mtrrt;
int lx, ly, rx, ry, btn, dir;
//pin constants
DigitalOut mtctl(p26); //motor controller power
PwmOut lpwm(p22); //PWM for left motors
PwmOut rpwm(p21); //PWM for right motors
DigitalOut rfor(p28); //right forward enable
DigitalOut lfor(p30); //left forward enable
DigitalOut rrev(p27); //right reverse enable
DigitalOut lrev(p29); //left reverse enable
while(1) // infinite while loop. to be changed to contitional statement that will only run if valid serial data is present.
{pc.printf("I'm alive!");
// xbee.scanf( "%3d%3d%3d%3d%4d%4d\n", &lx, &ly, &rx, &ry, &dir, &btn);
//xbee.getc();
pc.scanf( "%3d%3d%3d%3d%4d%4d", &lx, &ly, &rx, &ry, &dir, &btn);
mtctl = 1;
//math for pwm dutycycle
mtrl = (ly * .00125);
mtrrt = (ry * .00125);
lpwm.period_ms(0.5);
lpwm.pulsewidth_ms(mtrl);
rpwm.period_ms(0.5);
rpwm.pulsewidth_ms(mtrrt);
pc.printf ("left y%f,motor%f\n", ly, mtrl);
//pc.printf ("motor%f\n", mtrl);
}
}
The code above doesnt work.
and the following will not work as well
#include "mbed.h"
int main()
{
Serial pc(USBTX, USBRX); // USBTX - Tranmit on USB USBRX - receive on USB
pc.baud(9600);
pc.format(8, Serial::None, 1);
pc.printf("I'm alive!");
//variables
float mtrl, mtrrt;
int lx, ly, rx, ry, btn, dir;
while(1) // infinite while loop. to be changed to contitional statement that will only run if valid serial data is present.
{
pc.scanf( "%3d%3d%3d%3d%4d%4d", &lx, &ly, &rx, &ry, &dir, &btn);
pc.printf ("left y%f,motor%f\n", ly, mtrl);
//pc.printf ("motor%f\n", mtrl);
}
}
I am trying to parse a string (it may be an array, I havent a clue what the diffrence is).
Its composed of 6 diffrent numeric values. the first 4 values are 3 digits long, while the last 2 are 4 digits each. there is nothing seperating the values, so the string will look like so: 11122233344455556666 with a line feed at the end.
I need to chop it up and store it in 6 variables. I have came up with the following but cant get it to work.
I am trying to printf the variable "thingy" to test if the string s being parsed. I get nothing back in in my terminal program, but I do get "hello world" that I put into the code before my while loop.
Any help is welcomed.