Quick question. Currently when I run my code I tap the button and it sends all of the tweets in one shot (every time it loops. How do I make it only send one tweet each time the button is pressed?
I think the problem is here...
for (int i = 0; i < 4; i++){
if (twitter.post(buttonPressed[i]))
full code
#include <Twitter.h>
#include <SPI.h>
#include <Ethernet.h>
// Ethernet Shield Settings
byte mac[] = { blahblahblahblahblah };
// If you don't specify the IP address, DHCP is used(only in Arduino 1.0 or later).
byte ip[] = { blahblahblahblahblah };
// Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
Twitter twitter("blahblahblahblahblahblahblah");
//which pins are used as INPUT/OUTPUT
const int buttonPin = 2;
const int ledPin = 13;
//Set the buttons state to 0 to start
int buttonState = 0;
// Messages to post
char* buttonPressed[] = {"please work"," come on, please!", "I hope it works", "come on you swine!"};
void setup ()
{
delay(1000);
Ethernet.begin(mac);
Serial.begin(9600);
Serial.println("connecting ...");
//what the pins are used as
pinMode (ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop()
{
//buttonState is the reading from the input buttonPin
buttonState = digitalRead(buttonPin);
//if the button is pressed,
if (buttonState ==HIGH){
//turn the light on
digitalWrite(ledPin, HIGH);
//and tweet
Serial.println("button pressed");
for (int i = 0; i < 4; i++){
if (twitter.post(buttonPressed[i])) {
int status = twitter.wait();
if (status ==200){
Serial.println("Tweeted!");
} else {
Serial.print("failed : code ");
Serial.println(status);
}
}else {
Serial.println("connection failed");
}
}
}
else{
}
}