Temboo and Twitter

Having already constructed a vision for my final, I used project 11 to play around and test some of the available components I will be using for my final. As a result I attempted to make a program that would tweet depending on whether or not a force resistor was pressed. I learned how to make arrays and how to store strings in them, and then created a list of a few things that I wanted the computer to tweet. After that I tested it by creating a interface on processing that changed the words depending on if you pressed the resistor or not. When I was finished with that I simply linked it to twitter instead of the interface. As I was testing it somehow, I ended up using all of my available data for Temboo. Luckily that data resets every month so for my final project I will test it simply using processing until my Temboo data limit refreshes. Below are some images of the tweets sent by the force resistor as well as the initial project to send a tweet just from Temboo’s processing code.

Tweeting through my aurdino and force resistor

As the values increase (as you press the resistor) it scrolls through the list of phrases to potentially say.
changing values twitter 3 good please

When you let go the visible phrase changes to the last one you stopped at. Once you hold the resistor down again the process continues.
vidddd2

 

 

The results can be seen on the screen and, as I programmed it to, as a tweet.
Screenshot_2014-11-16-23-35-22

My code can be seen down below.

Processing Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// This program will relay a series of six phrases when the user presses a pressure sensor
 
// Import the Serial library and create a Serial port handler
import processing.serial.*;
Serial myPort;   
 
 
import com.temboo.core.*;
import com.temboo.Library.Twitter.Tweets.*;
 
// Create a session using your Temboo account application details
TembooSession session = new TembooSession("ritznrubble", "myFirstApp", "1d8cccc701d3473282acd6d52044d86b");
 
 
 
int valueA;  // Sensor Value A
int valueB;  // Sensor Value B
 boolean a=false;
 float i; 
//------------------------------------
int y= 0;
int update=0;
int mapA;
int valA=0;
String[] sayings= new String[6];
//tracking if c is equal to y or if the value of y changes
int c=y;
int count=0;
void setup(){
 
  runStatusesUpdateChoreo();
 
  size(250,200);
  // List my available serial ports
  int nPorts = Serial.list().length; 
  for (int i=0; i < nPorts; i++) {
    println("Port " + i + ": " + Serial.list()[i]);
  }
 
   String portName = Serial.list()[0]; 
  myPort = new Serial(this, portName, 9600);
  serialChars = new ArrayList();
 
  //array of sayings
 
sayings [0]= "That hurts!";
sayings [1]= "Stop pushing!";
sayings [2]= "Pull back!";
sayings [3]= "Under Pressure";
sayings [4]= "So much stress!";
sayings [5]= "The pain!";
}
 
void draw(){
  processSerial();
 
background(0);
fill(255);
 println("check c", c, "check y", y, "check count:", count, "valueA", valueA, "ValA", valA, "mapA", mapA, "update", update);
 
   text(sayings[update],100,height/2);
//
 if (valueA==0){
  a=!a;
 } 
 
 
if (!a){
 
   i= random(6);
   y= (int)i;
 count=count+1; 
    c=y; 
    update=-1;
 
 
}else{
  a=false;
 update= c; 
 } while(update==c){
   runStatusesUpdateChoreo();
 
 
 }
   Math.round(y);
 
}
 
 
 
void runStatusesUpdateChoreo() {
 
 
  // Create the Choreo object using your Temboo session
  StatusesUpdate statusesUpdateChoreo = new StatusesUpdate(session);
 
  // Set credential
  statusesUpdateChoreo.setCredential("Test");
 
  // Set inputs
  statusesUpdateChoreo.setAccessToken("569521804-FioaGf2pkeT2DIECqmW1jqhrxnHLiaFepyUhnhSL");
  statusesUpdateChoreo.setAccessTokenSecret("M4DQwCeSZPJBN5Pn8YLmB3RLRXpXk3Ec9zx6AMoDOtCur");
  statusesUpdateChoreo.setConsumerSecret("4XapePIoUgWMEeRet54J7Vtnsvt8gYGBONqXNIeG8ZOKqQDjyn");
  statusesUpdateChoreo.setStatusUpdate(sayings[update]);
  statusesUpdateChoreo.setConsumerKey("PQZOI9BpDdu3txrFVSzVdQZfG");
 
  // Run the Choreo and store the results
  StatusesUpdateResultSet statusesUpdateResults = statusesUpdateChoreo.run();
 
 
 
}
 
 
//---------------------
 
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?
 
void processSerial() {
 
  while (myPort.available () > 0) {
    char aChar = (char) myPort.read();
 
    // You'll need to add a block like one of these 
    // if you want to add a 3rd sensor:
    if (aChar == 'A') {
      bJustBuilt = false;
      whichValueToAccum = 0;
    } else if (aChar == 'B') {
      bJustBuilt = false;
      whichValueToAccum = 1;
    } else if (((aChar == 13) || (aChar == 10)) && (!bJustBuilt)) {
      // If we just received a return or newline character, build the number: 
      int accum = 0; 
      int nChars = serialChars.size(); 
      for (int i=0; i < nChars; i++) { 
        int n = (nChars - i) - 1; 
        int aDigit = ((Integer)(serialChars.get(i))).intValue(); 
        accum += aDigit * (int)(pow(10, n));
      }
 
      // Set the global variable to the number we captured.
      // You'll need to add another block like one of these 
      // if you want to add a 3rd sensor:
      if (whichValueToAccum == 0) {
        valueA = accum;
        // println ("A = " + valueA);
      } else if (whichValueToAccum == 1) {
        valueB = accum;
        // println ("B = " + valueB);
      }
 
      // Now clear the accumulator
      serialChars.clear();
      bJustBuilt = true;
 
    } else if ((aChar >= 48) && (aChar <= 57)) {
      // If the char is between '0' and '9', save it.
      int aDigit = (int)(aChar - '0'); 
      serialChars.add(aDigit);
    }
  }
}

Aurdino Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// This Arduino program reads  signals, 
// such as from the force resistor 
 
 
int sensorValue1 = 0;  // variable to store the value coming from the other sensor
 
void setup() {
  Serial.begin(9600);  // initialize serial communications    
}
 
void loop() {
 
  // Read the value from the sensor 
 
  sensorValue1 = analogRead (A1);  // reads value from Analog input 1    
 
 
  Serial.print ("A"); 
  Serial.println (sensorValue1);  
 
  delay (50);   // wait a fraction of a second, to be polite
}
 
/*
 
*/

Earlier

For my initial test on using twitter (before making this program), I had processing tweet, “Well did it work?”.
Screenshot_2014-11-16-21-45-40

Comments are closed.