Hardware Reference
In-Depth Information
The pause() and resume()
methods use an external file saved
to your device to save variables that
persist when the sketch restarts. Each
variable is a separate string, saved
on its own line. A newline character
( \n ) separates each line. Figure 10-14
shows the results.
8
void pause() {
// make a string of the ball position:
String ballPos = ballX+ "\n" + ballY;
/// put the string in an array and save to a file:
String[] data = {
ballPos
};
saveStrings(datafile, data);
}
void resume() {
//load the data file:
String[] data = loadStrings(datafile);
// if there's a file there:
if (data != null) {
// and there are two strings, get them for X and Y:
if (data.length > 1) {
ballX = float(data[0]);
ballY = float(data[1]);
}
}
}
Play around with some of the Android examples
that come with Processing as well. The Accel-
erometer and Compass sketches are good fun,
and they show you how to get at those useful components
on your phone. Once you're familiar with Processing for
Android, you're ready to make your own datalogger on the
phone.
Figure 10-15
The Processing for Android sketch that you just wrote.
 
Search WWH ::




Custom Search