How to send a number as a number or How to rule an LED
Thomas McGrath III
mcgrath3 at mac.com
Fri Feb 4 12:38:32 EST 2011
Is this right?
char cmd[255];
int param = 0;
char buf[255];
int bufloc = 0;
while ( true )
{
buf[ bufloc ] = Serial.Read();
if ( buf[ bufloc ] == 13 ) // CR EOL
{
sscanf( buf, "%s %i", cmd, ¶m );
if ( !strcmp( cmd, "LED" ) ) // if cmd == "LED"
DoLed( param );
else if ( !strcmp( cmd, "BEEP" ) ) // if cmd == "BEEP"
DoBeep( param );
memset( buf, 0, sizeof( buf ) ); // clear the buffer
bufloc = 0; // start at the beginning again
}
else
{
++bufloc; // next read will go in the next buf char
if ( bufloc > 255 )
{
// ERROR - buffer overflow - line too long - missing CR? (print
something...)
memset( buf, 0, sizeof( buf ) );
bufloc = 0;
}
}
-- Tom McGrath III
http://lazyriver.on-rev.com
3mcgrath at comcast.net
On Feb 4, 2011, at 12:35 PM, Thomas McGrath III wrote:
> Well, Thank you very much the numtochar worked perfectly. SInce most of these are either two or three numbers being sent for motor/stepper and LED and will not be more than 255 I will stick with the numtochar() for this. I will still try to come up with a parser for the Arduino for passing commands and arguments but a tleast for now I am Beating that LED into submission and am very happy about it.
>
>
>
> -- Tom McGrath III
> http://lazyriver.on-rev.com
> 3mcgrath at comcast.net
>
> On Feb 4, 2011, at 12:23 PM, form wrote:
>
>> On Fri, Feb 4, 2011 at 12:18 PM, form <form at nonsanity.com> wrote:
>>
>>>
>>> else
>>> ++bufloc; // next read will go in the next buf char
>>
>>
>> For safety's sake...
>>
>> else
>> {
>> ++bufloc; // next read will go in the next buf char
>> if ( bufloc > 255 )
>> {
>> // ERROR - buffer overflow - line too long - missing CR? (print
>> something...)
>> memset( buf, 0, sizeof( buf ) );
>> bufloc = 0;
>> }
>> }
>>
>> Looking at that code and knowing that error would crash it... I couldn't
>> stand it anymore. :)
>>
>> ~ Chris Innanen
>> ~ Nonsanity
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
More information about the use-livecode
mailing list