/* Post a simple message to Twitter */
#include <Ethernet.h>
#include <Twitter.h>
#include <string.h> //strcat/strcpy @ http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1234640883
#include <stdlib.h> //”
Twitter twitter(“iKu575:making”); // this was YourID:Password in 1.0.1
const int lightPin = 2; // light sensor input
const int soundPin = 3; //mic sensor input
const int tempPin = 4; // temp sensor input
const int buttonPin = 13; //this is the button input
char lightStr1[ ] = “blinded by the light / “; // carriage return or new line
char lightStr2[ ] = “fields of gold, abound / “;
char lightStr3[ ] = “in the candlelight / “;
char tempStr1[ ] = “a sweaty sarcophagus / “;
char tempStr2[ ] = “not too cold but not too hot / “;
char tempStr3[ ] = “bone-chilling, penguins march on / “;
char soundStr1[ ] = “blaring in the wind”;
char soundStr2[ ] = “with perfect hearing”;
char soundStr3[ ] = “muted baby’s breath”;
char haikubuffer[140];
//variables that will change
int lightValue = 0;
int soundValue = 0;
int tempValue = 0;
int buttonState = 0;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 142, 150, 149, 160 }; // this is the ip within my lan
byte gateway[] = { 192, 168, 2, 1 }; // neccessary to get access to the internet via your router
byte subnet[] = { 255, 255, 255, 0 };
byte server[] = { 128, 121, 146, 100 }; // Twitter’s ip
void setup()
{
Ethernet.begin(mac, ip, gateway, subnet);
Serial.begin(9600);
delay(1000);
Serial.println(“connecting …”);
}
void loop ()
{
buttonState = digitalRead(buttonPin);
soundValue = analogRead(soundPin);
lightValue = analogRead(lightPin);
tempValue = analogRead(tempPin);
if (buttonState == HIGH) {
for (int x=0; x<140; x++) //inialize- condition- action
{
haikubuffer[x]=’ ‘; //clear buffer of old haiku before new input
}
//—-LIGHT VALUE—————————————-
if (lightValue >= 500) {
Serial.println(lightStr1);
strcat (haikubuffer, lightStr1);
delay(900);
}
else if (lightValue <= 499) {
Serial.println(lightStr3);
strcat (haikubuffer, lightStr3);
delay(900);
}
// else
// Serial.println(lightStr2);
// strcat (haikubuffer, lightStr2);
// delay(900);
//——TEMP VALUE——————————————
if (tempValue >= 181) {
Serial.println(tempStr1);
strcat (haikubuffer, tempStr1);
delay(900);
}
else if (tempValue <=179 ) {
Serial.println(tempStr3);
strcat (haikubuffer, tempStr3);
delay(900);
}
// else
// Serial.println(tempStr2);
// strcat (haikubuffer, tempStr2);
// delay (900);
//—–SOUND VALUE—————————————
if (soundValue >= 800) {
Serial.println(soundStr3);
strcat (haikubuffer, soundStr1);
delay(900);
}
else if (soundValue <= 799) {
Serial.println(soundStr3);
strcat (haikubuffer, soundStr3);
delay(900);
}
// else
// Serial.println(soundStr2);
// strcat (haikubuffer, soundStr2);
// delay (900);
//——–TWITTER POST—————————————
if (twitter.post(haikubuffer)) {
int status = twitter.wait();
if (status == 200) {
Serial.println(“OK.”);
} else {
Serial.print(“failed : code “);
Serial.println(status);
}
} else {
Serial.println(“connection failed.”);
}
delay(3000);
Serial.println(haikubuffer);
}
}
