/* Button Turns on and off a light emitting diode(LED) connected to digital pin 13, when pressing a pushbutton attached to pin 2. The circuit: * LED attached from pin 13 to ground * pushbutton attached to pin 2 from +5V * 10K resistor attached to pin 2 from ground * Note: on most Arduinos there is already an LED on the board attached to pin 13. created 2005 by DojoDave modified 28 Oct 2010 by Tom Igoe This example code is in the public domain. http://www.arduino.cc/en/Tutorial/Button */ #if defined(ARDUINO) && ARDUINO > 18 // Arduino 0019 or later #include #endif #include #include #include #include // Ethernet Shield Settings byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // substitute an address on your own network here byte ip[] = { 192, 168, 1, 177 }; // Your Token to Tweet (get it from http://arduino-tweet.appspot.com/) Twitter twitter("<<< YOUR TOKEN HERE >>>"); // Message to post char msg[] = "testing3"; // not being used // constants won't change. They're used here to // set pin numbers: const int buttonPin = 2; // the number of the pushbutton pin const int ledPin = 13; // the number of the LED pin int randNumber = 0; // random number to display in the tweet // variables will change: int buttonState = 0; // variable for reading the pushbutton status void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); delay(1000); Ethernet.begin(mac, ip); Serial.begin(9600); Serial.println("connecting ..."); } void loop(){ // read the state of the pushbutton value: buttonState = digitalRead(buttonPin); // check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (buttonState == HIGH) { // turn LED on: digitalWrite(ledPin, HIGH); char buffer[140] = {0}; //Setup the PString function PString mystring(buffer, sizeof(buffer)); randNumber = random(100,999); mystring.print("Testing..."); mystring.println(randNumber); if (twitter.post(buffer)) { // 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); delay(5000); if (status == 200) { Serial.println("OK."); } else { Serial.print("failed : code "); Serial.println(status); } } } else { // turn LED off: digitalWrite(ledPin, LOW); Serial.println("waiting..."); } }