// hello.txrx.45.pde // receive and display transmit-receive step response // Example by Neil Gershenfeld // Adapted for Processing 2+ by Nathan Melenbrink // Further adapted for Twitter by Cody Glen // Using methods referenced from Tom Igoe's examples //import twitter stuff import twitter4j.conf.*; import twitter4j.*; import twitter4j.auth.*; import twitter4j.api.*; import java.util.*; //import serial import processing.serial.*; //start twitter instance Twitter twitter; //twitter string to tweet String[] tweets = { "I appear to be dry; I need a Brew!", "Bartender! Brew Me!", "Pour me in!", "Beer! Please!", "Much Thirst. Wow.", "I need a Brawndo; The THIRST MUTILATOR... jk Beer Me.", "Whiskey!... Oh wait, I mean a Brew please.", "What do you have on tap/on draft?", "Do you have anything light on tap? ... Cool, I'll have a Guiness", "THEY'RE MINERALS MARIE!", "Do you have anything dark on draft?", "Do you have anything local? I wanna Taste The Rainbowâ„¢ ", "Is that imported? Awesome. Let's do it.", "How much is my tab up to, Jeez!", "Can i get a glass of water?..... Jk Pour me another.", "Can you call me a taxi? Uber is too hard to do right now....", }; //var Serial myPort; // The serial port float eps = 0.75; // filter fraction float filt = 0.0; // filtered value int mult = 3; int byte1, byte2, byte3, byte4, up_low, up_high, down_low, down_high; //setup void setup() { size (800, 450); //configure twitter ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey("Qia1eO9T5wB2mUHBqN2r04qvb"); cb.setOAuthConsumerSecret("G7eUOSZx3qSUeIs4FI0OxGiXg0FGdobF5n2rcaPxVW100vZvBO"); cb.setOAuthAccessToken("809127396054077440-O4TzwW4DFsyyD0cblqQHiDURbVTZzuC"); cb.setOAuthAccessTokenSecret("lmFpKaudiyGPobzfJnN20rwasbAVQXndZX2tXVbPHvzcl"); TwitterFactory tf = new TwitterFactory(cb.build()); twitter = tf.getInstance(); // List all the available serial ports printArray(Serial.list()); // Open the port you are using at the rate you want: // If you have multiple serial devices connected, you might need to change the [0] to the appropriate device myPort = new Serial(this, Serial.list()[0], 9600); // Initialize variables byte1 = byte2 = byte3 = byte4 = up_low = up_high = down_low = down_high = 0; } //draw void draw() { // find framing while (true){ delay(10); byte1 = byte2; byte2 = byte3; byte3 = byte4; byte4 = up_low; up_low = up_high; up_high = down_low; down_low = down_high; down_high = myPort.read(); // once past the framing bytes, perform calculations and render if (byte4 == 4){ int up_value = 256*up_high + up_low; int down_value = 256*down_high + down_low; int value = (up_value - down_value) * mult; filt = (1-eps)*filt + eps*value; int x = int((.9-.2)*width*filt/ 10000.0); background(0); // set background color as black textSize(24); textAlign(LEFT, CENTER); fill(255); // text color text(filt, 10, 0.5*height); fill(100); // rect1 color rect(0.3*width, 0.05*height, x, 0.9*height); fill(50); // rect2 color rect(x + 0.3*width, 0.05*height, 0.65*width -x, 0.9*height); if(value <= 2048){ tweet(); delay(600000); } print(value+" "); break; } } } //tweet void tweet(){ try{ int count = int(random(tweets.length)); Status status = twitter.updateStatus(tweets[count]); System.out.println("Status updated to [" + status.getText() + "]."); } catch (TwitterException te){ System.out.println("Error: "+ te.getMessage()); } }