Connecting Serials and Twitter
in
Contributed Library Questions
•
1 year ago
Hi, I have an Arduino Program that spits out serial numbers up to 255 depending on a force sensor and I'm trying to make it so that, using the twitter4j library, depending on the serial numbers, it will tweet certain things. Problem is I'm not sure how to get Processing to read the serial numbers or how to make it tweet. I've tried to, but I am TERRIBLE with code and I keep getting errors. I've tried a few tutorials and tried to incorporate them into my code, but I just don't get it. Here's my code (sans access codes and such). Can anyone please help me? I need this for a project due Wednesday.
- ArrayList<String> words = new ArrayList();
- import processing.serial.*;
- Serial myPort;
- import processing.serial.*;
- import twitter4j.conf.*;
- import twitter4j.internal.async.*;
- import twitter4j.internal.org.json.*;
- import twitter4j.internal.logging.*;
- import twitter4j.http.*;
- import twitter4j.api.*;
- import twitter4j.util.*;
- import twitter4j.internal.http.*;
- import twitter4j.*;
- void setup() {
- //Set the size of the stage, and the background to black.
- size(550,550);
- background(0);
- smooth();
- String portName = Serial.list()[0];
- myPort = new Serial(this, portName, 9600);
- myPort.bufferUntil('\n');
- //Credentials
- ConfigurationBuilder cb = new ConfigurationBuilder();
- cb.setOAuthConsumerKey("???");
- cb.setOAuthConsumerSecret("???");
- cb.setOAuthAccessToken("???");
- cb.setOAuthAccessTokenSecret("???");
- Twitter twitter = new TwitterFactory(cb.build()).getInstance();
- }
- void draw() {
- background(0);
- text("simpleTweet_00", 18, 45);
- text("@msg_box", 30, 70);
- listenToArduino();
- }
- void listenToArduino() {
- String msgOut = "";
- int arduinoMsg = Serial.read();
- if (arduinoMsg >= 50 && < 150) {
- msgOut = "TextTweet1";
- }
- if (arduinoMsg >= 150 && <= 200) {
- msgOut = "TextTweet2";
- }
- if (arduinoMsg >= 220) {
- msgOut = "TextTweet3";
- }
- compareMsg(msgOut); // this step is optional
- // postMsg(msgOut);
- }
1