Using Multiple Twitter Accounts

One way to share code between multiple Twitter objects is to use a pointer to a Twitter object, like this:

#include <SPI.h> // needed in Arduino 0019 or later
#include <Ethernet.h>
#include <Twitter.h>

// The includion of EthernetDNS is not needed in Arduino IDE 1.0 or later.
// Please uncomment below in Arduino IDE 0022 or earlier.
//#include <EthernetDNS.h>


// Ethernet Shield Settings
byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// If you don't specify the IP address, DHCP is used(only in Arduino 1.0 or later).
byte ip[] = { 
  192, 168, 1, 177 };

// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)

Twitter twitterWithTokenOne("my first token");
Twitter twitterWithTokenTwo("my second token");

void setup()
{


  delay(1000);
  Ethernet.begin(mac, ip);
  // or you can use DHCP for automatic IP address configuration.
  // Ethernet.begin(mac);
  Serial.begin(9600);


}

void loop()
{
  Twitter *twitter;
  char *msg;

  for (int account = 0; account < 2; account++) {
    Serial.println("connecting ...");
    Serial.print("Account=");
    Serial.println(account);

    switch (account) {
    case 0: 
      msg = "This should tweet from first Account @r4rob ";
      twitter = &twitterWithTokenOne;
      Serial.print("Tweeting Using 0 =");
      Serial.println(account);
      break;

    case 1:
      msg = "This should tweet from second Account @r4rob ";
      twitter =  &twitterWithTokenTwo;
      Serial.print("Tweeting Using 1 =");
      Serial.println(account);  
      break;
    }


    if (twitter->post(msg)) {
      // Specify &Serial to output received response to Serial.
      // If no output is required, you can just omit the argument, e.g.
      // int status = twitter.wait();
      int status = twitter->wait(&Serial);
      if (status == 200) {
        Serial.println("OK.");
      } 
      else {
        Serial.print("failed : code ");
        Serial.println(status);
      }
    }
  }
  while(true);   // Wait here forever
}