Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sending integer value with USB.send
12-05-2014, 08:03 AM,
#1
Sending integer value with USB.send
Info:
x4-easy-rev999
Bootloader_v4.14_18f4550_X20MHz

Hello guys, I'm new with pinguino and I have a question, what is the correct syntax to send integer values with USB.send ?

I tried with the code from the Wiki but is not working:

int level[1];
void setup()
{
level[0] = 0;
}
void loop()
{
USB.send((uchar *)level,2); //error is here
level[0]++;
delay(300);
}

To read the value I'm using a code similar to USB_bulk_read_from_pinguino.py from Examples

What I'm trying to do is read the values from a sensor and send those values, I did it with CDC and is working but I don't know how to do it with USB.send

Some help guys, thank you.
Reply
12-05-2014, 03:28 PM, (This post was last modified: 13-05-2014, 12:43 AM by Pinguino.)
#2
RE: Sending integer value with USB.send
I think the following code is going to work

Code:
int level;
char buf[2];
void setup()
    {
    level = 0;
    }

void loop()
    {
    buf[1] = (char) level /256; //MSB
    buf[0] = (char) level%256; //LSB
    USB.send(buf,2); //type of "buf" must be char or u8
    level++;
    delay(300);
    }

We have to rebuild int level according the soft you use side PC as for instance:

level = buf[0] + 256*buf[1];

Good luck !
André

[Edited to remove unncessary quoting of previous post; code tags added]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)