TWEETING OBJECTO
I decided to do the button that tweets. It took me some time to figure out the code but with the help of Luca, I was able to successfully tweet with the press of a button. In my code, I decided to have the arduino Serial print an “A” when ever the button was down and then have Processing read that “A” and then post a status to twitter.
<iframe width=”560″ height=”315″ src=”//www.youtube.com/embed/7m2t1GF-ueM” frameborder=”0″ allowfullscreen></iframe>
Arduino
const int buttonPin = 2;
// variables will change:
int buttonState = 0;
int buttonPressed = 0;// variable for reading the pushbutton status
void setup() {
Serial.begin(9600); // initialize serial communications
}
void loop(){
buttonState = digitalRead (buttonPin);
if (buttonState==1 && buttonPressed==0){
Serial.println("A");
buttonPressed=1;
}
else if (buttonState==0 && buttonPressed==1) {
buttonPressed=0;
}
delay (10); // wait some number of milliseconds
}
Processing
import processing.serial.*;
import com.temboo.core.*;
import com.temboo.Library.Twitter.Tweets.*;
Serial myPort;
ArrayList serialChars; // Temporary storage for received serial data
int whichValueToAccum = 0; // Which piece of data am I currently collecting?
boolean bJustBuilt = false; // Did I just finish collecting a datum?
// Create a session using your Temboo account application details
TembooSession session = new TembooSession("salexy", "myFirstApp", "111dc69fd5864a3e95ef1ed410610654");
void setup() {
int nPorts = Serial.list().length;
for (int i=0; i < nPorts; i++) { println("Port " + i + ": " + Serial.list()[i]); } String portName = Serial.list()[4]; myPort = new Serial(this, portName, 9600); serialChars = new ArrayList(); } void draw() { while (myPort.available () >0) {
char aChar = (char) myPort.read();
if (aChar=='A') {
//println ("hi");
runStatusesUpdateChoreo();
}
}
}
void runStatusesUpdateChoreo() {
// Create the Choreo object using your Temboo session
StatusesUpdate statusesUpdateChoreo = new StatusesUpdate(session);
// Set credential
statusesUpdateChoreo.setCredential("Pawalkerology");
// Set inputs
statusesUpdateChoreo.setAccessToken("1202876874-AcWWhnbZYZHGMPhDNPRBfXHhrXfEQxIn5P3KK8W");
statusesUpdateChoreo.setAccessTokenSecret("JN1DpjlZ6tKZ8II676KJB2cZL5kqgw7DxAOcMctj72CGZ");
statusesUpdateChoreo.setConsumerSecret("K2jfW0ANoGzMowlHABOov3evxzI10C8HxMCuX7PFSvb5OLGb0v");
statusesUpdateChoreo.setStatusUpdate("This Documentation Tho!");
statusesUpdateChoreo.setConsumerKey("B6QwcUz3de2dWGcq4wzqjqwHr");
// Run the Choreo and store the results
StatusesUpdateResultSet statusesUpdateResults = statusesUpdateChoreo.run();
// Print results
println(statusesUpdateResults.getResponse());
}