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.

Class

Messenger

Name

attach()

Examples
#include <Messenger.h>


// Instantiate Messenger object with the message function and the default separator 
// (the space character)
Messenger message = Messenger(); 

// Define the max size of the string
// The size must be big enough to hold the longest string you are expecting
#define MAXSIZE 30 

// Create a char array (string) to hold the received string
char string[MAXSIZE]; 



// Define messenger function
void messageCompleted() {
  // This loop will echo each element of the message separately
  while ( message.available() ) {
    message.copyString(string,MAXSIZE);
    Serial.print(string); // Echo the string
    Serial.println(); // Terminate the message with a carriage return
  }
  
  
}

void setup() {
  // Initiate Serial Communication
  Serial.begin(115200); 
  message.attach(messageCompleted);
}

void loop() {
  
  // The following line is the most effective way of 
  // feeding the serial data to Messenger
  while ( Serial.available() ) message.process( Serial.read() );
}
Description Attaches a callback function that is executed once a message is completed. This is the preferred way of working with Messenger (see example).
Syntax
attach(newFunction)
Parameters
newFunction The callback that gets called when a message is received.
Returns None
Usage Application
Updated on July 07, 2011 11:11:03pm PDT

Creative Commons License