Advertisement
franzkev

Twitter2 LCD (IO)

Sep 7th, 2014
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.88 KB | None | 0 0
  1. /*
  2.  * Twitter2LCD
  3.  * gets xml data from http://twitter.com/statuses/user_timeline/16297873.rss
  4.  * reads the most recent tweet from field:  <title>
  5.  * writes the output to the LCD.
  6.  
  7.  The circuit:
  8.  * LCD RS pin to digital pin 12
  9.  * LCD Enable pin to digital pin 11
  10.  * LCD D4 pin to digital pin 5
  11.  * LCD D5 pin to digital pin 4
  12.  * LCD D6 pin to digital pin 3
  13.  * LCD D7 pin to digital pin 2
  14.  * 10K resistor:
  15.  * ends to +5V and ground
  16.  * wiper to LCD VO pin (pin 3)
  17.  
  18.  See more here:
  19.  http://www.arduino.cc/en/Tutorial/LiquidCrystal
  20.  */
  21.  
  22.  
  23. #include <Ethernet.h>
  24. #include <EthernetDHCP.h>
  25. #include <TextFinder.h>
  26. #include <LiquidCrystal.h>
  27.  
  28. // initialize the library with the numbers of the interface pins
  29. LiquidCrystal lcd(9, 8, 5, 4, 3, 2);
  30.  
  31. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  32. byte server[] = {128,242,240,20}; // Twitter
  33.  
  34. char tweet[140];
  35.  
  36. Client client(server, 80);
  37.  
  38. TextFinder  finder( client );  
  39.  
  40. void setup()
  41. {
  42.   lcd.begin(20,4);
  43.   lcd.clear();
  44.   lcd.print("Twitter2LCD");
  45.   Serial.begin(9600);
  46.   EthernetDHCP.begin(mac);
  47. }
  48.  
  49.  
  50. void loop()
  51. {
  52.   lcd.clear();
  53.   if (client.connect()) {
  54.     client.println("GET http://www.twitter.com/statuses/user_timeline/16297873.rss HTTP/1.0");  // twitter rss for fgranelli
  55.     client.println();
  56.   }
  57.   else {
  58.     lcd.println("Connection failed");
  59.     Serial.println("Connection failed");
  60.   }
  61.   if (client.connected()) {
  62.      // get the last tweet by simply parsing the item and title tags
  63.      if((finder.find("<item>")&&(finder.getString("<title>","</title>",tweet,140)!=0)))
  64.      {  
  65.          Serial.println(tweet);
  66.          
  67.          for (int j=0; j<2; j++) {
  68.            // first part of the tweet
  69.            lcd.clear();
  70.            lcd.setCursor(0,0);
  71.            for (int i=0; i<20; i++)
  72.              lcd.print(tweet[i]);
  73.            lcd.setCursor(0,1);
  74.            for (int i=20; i<40; i++)
  75.              lcd.print(tweet[i]);
  76.            lcd.setCursor(0,2);
  77.            for (int i=40; i<60; i++)
  78.              lcd.print(tweet[i]);
  79.            lcd.setCursor(0,3);
  80.            for (int i=60; i<80; i++)
  81.              lcd.print(tweet[i]);
  82.            delay(10000);
  83.            // second part of the tweet
  84.            lcd.clear();
  85.            lcd.setCursor(0,0);
  86.            for (int i=60; i<80; i++)
  87.              lcd.print(tweet[i]);
  88.            lcd.setCursor(0,1);
  89.            for (int i=80; i<100; i++)
  90.              lcd.print(tweet[i]);
  91.            lcd.setCursor(0,2);
  92.            for (int i=100; i<120; i++)
  93.              lcd.print(tweet[i]);
  94.            lcd.setCursor(0,3);
  95.            for (int i=120; i<140; i++)
  96.              lcd.print(tweet[i]);
  97.            delay(10000);
  98.            }
  99.      }
  100.     else
  101.       lcd.println("Could not find item field");
  102.   }
  103.   else {
  104.     lcd.println("Disconnected");
  105.   }
  106.   client.stop();
  107.   client.flush();
  108.   delay(60000); // wait a minute before next update
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement