Hardware Reference
In-Depth Information
The global variables for
this sketch include: values
for the sensor reading interval, in
seconds, and the interval for updating
the server, in minutes; the times of
the last read and send; the address of
your server PHP script; the state of the
connection; two buttons for reading
and sending on demand; and the color
scheme for the app.
Send It
/*
Datalogger
Receives data via Bluetooth every ten seconds
Uploads data via HTTP every two minutes
Context: Processing, Android mode
*/
import cc.arduino.btserial.*;
// instance of the library:
BtSerial bt;
int readInterval = 10; // in seconds
int sendInterval = 2; // in minutes
int lastRead = second(); // the seconds last time you read
int lastSend = minute(); // the minutes last time you read
String lastSendTime; // String timestamp of last server update
8 Change this to match
your PHP script's URL.
// URL of your PHP Script:
String url = "http://www.yourserver.com/logger.php?data=";
String currentReadings = ""; // group of readings, with datestamps
String thisReading; // most recent reading
String connectionState = ""; // connected to Bluetooth or not?
Button readButton; // Button for prompting immediate read
Button sendButton; // Button for prompting immediate send
boolean updateNow = false; // flag to force an update
boolean sendNow = false; // flag to force a send
// color scheme from http://kuler.adobe.com
// deep optimism by nicanore:
color bgColor = #2B0D15;
color textColor = #FFEB97;
color buttonColor = #565F63;
color buttonHighlightColor = #ACBD9B;
The setup() method sets the back-
ground and fill colors, and initializ-
es the text parameters. Then, it makes
a new instance of the BtSerial library
and tries to connect to the Bluetooth
Mate using the connect() method.
Finally, it initializes the two onscreen
buttons.
8
void setup() {
// set color scheme:
background(bgColor);
fill(textColor);
// Setup Fonts:
String[] fontList = PFont.list();
PFont androidFont = createFont(fontList[0], 24, true);
textFont(androidFont, 24);
// instantiate the library:
bt = new BtSerial( this );
ยป
 
Search WWH ::




Custom Search