Friday, July 13, 2012

Tips for using NeoCat's Arduino Twitter library

This may be obvious to people who are better at programming than me, but I struggled to figure it out for a while. NeoCat's library can only post chars and char arrays to twitter, but readings are not in char format. To get around this I had to do some fiddly type conversions, which I lay out below.

itoa(var, varChar, 10);                               //converts 'var', which is an int, to 'varChar', which is a char
                                                                //If anyone can tell me what the '10' is for, please do

stringone = String(stringone + varChar  );    //make a string called stringone. Append the newly formed  
                                                                  //char 'varChar', which was the int 'var'.

   stringone.toCharArray(msg, 100);             //convert 'stringone' to char array (reads "value of the in
                                                                  //save the char array as 'msg'. 100 is the number of
                                                                  //characters in the char array.;                                       //posts data to twitter

'msg' must be declared as a char at the beginning of the sketch.

var was declared as an int, it could be, for instance, an analog reading.
varChar was declared as a char[].
stringone does not need to be declared until it is made.
More chars and char arrays can be added to stringone by using the + symbol and the char name.

No comments:

Post a Comment