Information Technology Reference
In-Depth Information
ITemperatureInput ourTempSensor = EDemoBoard.getADCTemperature();
double celsiusTemp = ourTempSensor.getCelsius();
double fahrTemp = ourTempSensor.getFahrenheit();
3.2.2.2
A SunSPOT “Blink” Application
As for TinyOS/nesC, we now present a Blink (Hello World) application for Sun
SPOTs.
package org.sunspotworld;
importcom.sun.spot.sensorboard.EDemoBoard;
importcom.sun.spot.sensorboard.peripheral.ISwitch;
importcom.sun.spot.sensorboard.peripheral.ITriColorLED;
importcom.sun.spot.util.*;
importjavax.microedition.midlet.MIDlet;
importjavax.microedition.midlet.MIDletStateChangeException;
public class Blink extends MIDlet {
private ITriColorLED [] leds =
eDemoBoard.getInstance().getLEDs();
protected void startApp() throws MIDletStateChangeException {
System.out.println(“Hello, world”);
ISwitch sw1 =
EDemoBoard.getInstance().getSwitches()[EDemoBoard.SW1];
leds[0].setRGB(100,0,0);
// set color to moderate red
while (sw1.isOpen()) {
// done when switch is pressed
leds[0].setOn();
// Blink LED Utils.sleep
(250);
// wait 1/4 seconds
leds[0].setOff();
Utils.sleep(1000);
// wait 1 second
}
notifyDestroyed();
// cause the MIDlet to exit
}
protected void pauseApp() {
// This is not currently called by the Squawk VM
}
protected void destroyApp(boolean unconditional) throws
MIDletStateChangeException {
for (int i = 0; i < 8; i++) {
leds[i].setOff();
}
}
}
3.2.2.3
Radio Stream and Datagram Connections
Sun SPOT SDK provides two ways to perform communication between two Sun SPOT
devices: the radiostream protocol and the radiogram protocol. The basic difference is
in guarantees of delivery: the radiostream protocol provides stream-based reliable
service, while the radiogram protocol makes no guarantees on delivery or ordering.
Search WWH ::




Custom Search