Libraries
\ Messenger
Reference for Wiring version 1.0 Build 0100+ If you have a previous version, use the reference included with your software. If see any errors or have any comments, let us know.
Name |
Messenger |
Examples |
#include <Messenger.h>
Messenger message = Messenger();
void messageCompleted()
{
if ( message.checkString("r") )
{
if ( message.checkString("a") )
{
Serial.print("a ");
for (char i=0;i<8;i++)
{
Serial.print(analogRead(i),DEC);
Serial.print(" ");
}
Serial.println();
}
else if ( message.checkString("d") )
{
Serial.print("d ");
for (char i=0;i<23;i++)
{
Serial.print(digitalRead(i),DEC);
Serial.print(" ");
}
Serial.println();
}
}
else if ( message.checkString("w") )
{
if ( message.checkString("a") )
{
int pin = message.readInt();
int value = message.readInt();
analogWrite(pin,value);
}
else if ( message.checkString("d") )
{
int pin = message.readInt();
int state = message.readInt();
digitalWrite(pin,state);
}
}
else if ( message.checkString("p") && message.checkString("m") )
{
int pin = message.readInt();
int mode = message.readInt();
pinMode(pin,mode);
}
}
void setup()
{
Serial.begin(115200);
message.attach(messageCompleted);
}
void loop()
{
while (Serial.available()) message.process(Serial.read());
}
|
Description |
Messenger is a "toolkit" that facilitates the parsing of ASCII messages. Messenger buffers characters until it receives a carriage return (CR). It then considers the message complete and available. The message is split into many elements as defined by a separator. The default separator is the space character, but can be any character other than NULL, LF or CR. |
Syntax |
Messenger(separator)
|
Methods |
|
Parameters |
separator |
The separator is what deliminates the messages into elements. |
|
|
|
Returns |
None |
Usage |
Application |
Updated on July 07, 2011 11:11:02pm PDT