jar
file will automatically be copied to a local folder named
code
.) That’s all you
have to do to give your application access to the Twitter4J library.
We proceed with some boilerplate code:
Ethernet/TweetTemperature/TweetTemperature.pde
import processing.serial.*;
final float MAX_WORKING_TEMP = 32.0;
final int LINE_FEED = 10;
final int BAUD_RATE = 9600;
final int FONT_SIZE = 32;
final int WIDTH = 320;
final int HEIGHT = 240;
final String API_KEY = "<YOUR API KEY>";
final String API_SECRET = "<YOUR API SECRET>";
final String ACCESS_TOKEN = "<YOUR ACCESS TOKEN>";
final String ACCESS_TOKEN_SECRET = "<YOUR ACCESS TOKEN SECRET>";
Serial _arduinoPort;
float _temperature;
boolean _isCelsius;
PFont _font;
void setup() {
size(WIDTH, HEIGHT);
_font = createFont("Arial", FONT_SIZE, true);
println(Serial.list());
_arduinoPort = new Serial(this, Serial.list()[0], BAUD_RATE);
_arduinoPort.clear();
_arduinoPort.bufferUntil(LINE_FEED);
_arduinoPort.readStringUntil(LINE_FEED);
}
void draw() {
background(255);
fill(0);
textFont(_font, FONT_SIZE);
textAlign(CENTER, CENTER);
if (_isCelsius)
text(_temperature + " \u2103", WIDTH / 2, HEIGHT / 2);
else
text(_temperature + " \u2109", WIDTH / 2, HEIGHT / 2);
}
As usual, we import the serial libraries for communicating with the Arduino,
and then we define some constants we’ll need later. Most of them contain the
credentials we need to access the Twitter service. With
MAX_WORKING_TEMP
, you
can define at which temperature the application starts to Tweet. This can be
a degrees Celsius or Fahrenheit value. The rest defines a few values we need
report erratum • discuss
Tweeting Messages with Processing • 169
www.it-ebooks.info