//############ Vars para Interface ################### import controlP5.*; ControlP5 controlP5; int myColorBackground = color(30,30,30); int corTitulo = color(40,100,155); int corSubtitulo = color(54,132,55); Textfield usernameTXB; Textfield passwordTXB; Textlabel tituloLABEL; Textlabel subtituloLABEL; //############ Vars para ligar ao Arduino e para o twitter ################ import simpleML.*; import processing.serial.*; int time; String lasttweet; String tweet; String[] check; String[] titulo; Serial port; int rate; Twitter twitter; User[] friends; //String username; //String password; String username = "Birduino"; String password = "passarito"; java.util.List statuses = null; //FUNÇÃO PARA O SUBMIT DOS VALORES DAS CAIXAS DE TEXTO void controlEvent(ControlEvent theEvent) { username = usernameTXB.getText(); password = passwordTXB.getText(); //println("\n\n Username: "+ usernameTXB.getText() + "\nPassword: " + passwordTXB.getText()); //delay(5000); } void setup(){ //#########CONFIGURA O INTERFACE############### size(400,300); frameRate(30); controlP5 = new ControlP5(this); usernameTXB = controlP5.addTextfield("Username",100,160,200,20); usernameTXB.setFocus(true); passwordTXB = controlP5.addTextfield("Password",100,200,200,20); passwordTXB.setPasswordMode(true); subtituloLABEL = controlP5.addTextlabel("label","complete the following fields.",20,134); subtituloLABEL.setColorValue(corSubtitulo); tituloLABEL = new Textlabel(this, "Welcome to Birduino.",20,100,400,200,0xffff0000,ControlP5.synt24); tituloLABEL.setLetterSpacing(3); tituloLABEL.setColorValue(corTitulo); //########## CONFIGURA A LIGAÇÃO AO TWITTER ############### twitter = new Twitter(username,password); println("Starting timer..."); int time = 0; lasttweet = " "; port = new Serial(this, Serial.list()[1], 9600); } void draw() { //########## Desenhar o interface ################# background(myColorBackground); tituloLABEL.draw(this); //se as variáveis de utilizar e password não estiverem preenchidas, nao corre o timer if(username != null && password != null){ //######## Timer para correr a função tweets(); ########## time++; if (time>=120) { tweets(); time=0; } } else { println("introduzir dados"); } } void tweets(){ //Coloca a friend time line na var statuses try { statuses = twitter.getFriendsTimeline(); } catch( TwitterException e) { println(e.getStatusCode()); } Status status = (Status)statuses.get(0); tweet = status.getText(); println("Tweet actual: " + tweet); println("Tweet Anterior: " + lasttweet); //Mostra o rate limit try { rate = twitter.rateLimitStatus().getRemainingHits(); println("Rate limit: " + rate); } catch( TwitterException e) { println(e.getStatusCode()); } if (tweet.length() != lasttweet.length()) { println("==New Tweet==\n\n"); port.write('H'); } else { println("==No Activity==\n\n"); port.write('L'); } Status Lstatus = (Status)statuses.get(0); lasttweet = Lstatus.getText(); }