A Button that Tweets
Full disclosure: I went for the minimal project so that I can dedicate more time to the final.
This is my initial Temboo test, before the button was connected.
This test has the button connection. Now we have a tweeting button!
//Miranda Jacoby
//Electronic Media Studio Interactivity Section A
//majacoby@andrew@.cmu.edu
//Copyright Miranda Jacoby 2014
//Code created with help of Golan Levin
//With elements of the pushbutton example code
//created 2005
//by DojoDave <http://www.0j0.org>
//modified 30 Aug 2011
//by Tom Igoe
//http://www.arduino.cc/en/Tutorial/Button
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
Serial.begin(9600); // initialize serial communications
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead (buttonPin);
// print if the pushbutton is pressed.
// Serial.println (buttonState); writes the string "1" or "0"
Serial.print (buttonState);
delay (10); // wait some number of milliseconds
}
//Miranda Jacoby
//Electronic Media Studio Interactivity Section A
//majacoby@andrew@.cmu.edu
//Copyright Miranda Jacoby 2014
//Code created with help of Golan Levin and Temboo.
import com.temboo.core.*;
import com.temboo.Library.Twitter.Tweets.*;
import processing.serial.*;
Serial myPort; // Create object from Serial class
int currVal; // Data received from the serial port
int prevVal;
int tweetTime;
int currentTime;
// Create a session using your Temboo account application details
TembooSession session = new TembooSession("pigeon", "pigeontwitter", "2289511ed75e4578a3b71a4b693fdb03");
void setup() {
size(200, 200);
String portName = Serial.list()[5];
myPort = new Serial(this, portName, 9600);
currentTime = millis();
}
void draw() {
prevVal = currVal; // swap
if ( myPort.available() > 0) { // If data is available,
currVal = myPort.read(); // read it and store it in val
myPort.clear();
}
background(255); // Set background to white
if (currVal == 48) { // If the serial value is "0",
fill(0); // set fill to black
} else if (currVal == 49) { // If the serial value is not 0,
fill(240); // set fill to whiteish
} else {
fill(255, 0, 0);
}
rect(50, 50, 100, 100);
if (currVal != prevVal) {
if (currVal == 48) {
sendTweet();
} else if (currVal == 49) {
// println ("Released!");
}
}
}
void sendTweet(){
tweetTime = millis() - currentTime;
println ("I was pressed at " + tweetTime);
if (tweetTime > 1000){
println("Sucessful tweet");
//send tweet by running the StatusesUpdate Choreo function
runStatusesUpdateChoreo();
}
else {
println("To soon to tweet!");
}
currentTime = millis();
}
void runStatusesUpdateChoreo() {
// Create the Choreo object using your Temboo session
StatusesUpdate statusesUpdateChoreo = new StatusesUpdate(session);
// Set credential
statusesUpdateChoreo.setCredential("TweetButton");
// Set inputs
statusesUpdateChoreo.setAccessToken("2769267476-rHudd8EwU7uLhkcruAwHxJtzA5AB7EH9lwPFD7s");
statusesUpdateChoreo.setAccessTokenSecret("aIxNctSi3RXShSRn0iWfaDkE8NSN9OglhY4GgOU1gWRZy");
statusesUpdateChoreo.setStatusUpdate("Testing, for the second time: A button that tweets when you press it.");
// Run the Choreo and store the results
StatusesUpdateResultSet statusesUpdateResults = statusesUpdateChoreo.run();
// Print results
println(statusesUpdateResults.getResponse());
}