sven
8/14/2013 - 12:07 AM

Getting started with the Arduino Ethernet Twitter Library to send a Tweet to Twitter with a Button.

Getting started with the Arduino Ethernet Twitter Library to send a Tweet to Twitter with a Button.

void tweet(char msg[]) {
  Serial.println("connecting ...");
  if (twitter.post(msg)) {
    int status = twitter.wait(&Serial);
    if (status == 200) {
      Serial.println("OK.");
    } else {
      Serial.print("failed : code ");
      Serial.println(status);
    }
  } else {
    Serial.println("connection failed.");
  }
}
void setup() {
  pinMode(buttonPin, INPUT);
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
}
// Ethernet Settings
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // No need to change the default Mac address
byte ip[] = { 123, 456, 789, 0 }; // Insert your Ethernet IP

// OAuth Token
// Get your Token here: http://arduino-tweet.appspot.com/oauth/twitter/login
Twitter twitter("123456789-abcdefghijklmnopqrstuvwxyz");

// Counter
int i=0; // start with zero
char buf[100];

// Pin
int buttonPin = 9; // Pin for the push button
void loop() {
  if (digitalRead(buttonPin) == HIGH) {
    // convert everything to string(char)
    sprintf(buf, "This is tweet number %d via an #Arduino Ethernet Board!", i); 
    tweet(buf);
    i++;
    // zero delay
    delay(0);
  }
}
#include <SPI.h> // needed in Arduino 0019 or later
#include <Ethernet.h>
#include <Twitter.h>