Advertisement
mcarrasco

Periodic tweets using tweeter library for Arduino

Feb 7th, 2014
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.33 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Ethernet.h>
  3. #include <Twitter.h>
  4.  
  5. byte mac[] = {   0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // create MAC address for ethernet shield
  6. // Your Token to Tweet (get it from http://arduino-tweet.appspot.com/)
  7. Twitter twitter("14205607-aX34ti1eLI44r3dZpo2GtsI8YXf24M0sZSV7Taaaa");
  8.  
  9. int analogZero;
  10. char tweetText[140];
  11.  
  12. void setup()
  13. {
  14.   delay(5000);
  15.   Ethernet.begin(mac);
  16.   Serial.begin(9600);
  17. }
  18.  
  19. void tweet(char msg[])
  20. {
  21.   Serial.println("connecting ...");
  22.   if (twitter.post(msg))
  23.   {
  24.     // Specify &Serial to output received response to Serial.
  25.     // If no output is required, you can just omit the argument, e.g.
  26.     // int status = twitter.wait();
  27.     int status = twitter.wait(&Serial);
  28.     if (status == 200)
  29.     {
  30.       Serial.println("OK.");
  31.     }
  32.     else
  33.     {
  34.       Serial.print("failed : code ");
  35.       Serial.println(status);
  36.     }
  37.   }
  38.   else
  39.   {
  40.     Serial.println("connection failed.");
  41.   }
  42. }
  43.  
  44. void loop()
  45. {
  46.   // get some data from A0.
  47.   analogZero=analogRead(0);
  48.  
  49.   // assemble message to send. This inserts the value of "analogZero" into the variable "tweetText" at point %d
  50.   sprintf(tweetText, "Prueba Arduino, Pin Analog 0 tiene el valor: %d. ", analogZero); //
  51.  
  52.   delay(1000);
  53.   tweet(tweetText);
  54.   do{ }
  55.   while(1>0); // endless loop
  56.   delay(61000)
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement