Java Reference
In-Depth Information
* two bytes. Use "big-endian" mode with most
* significant byte sent first.
**/
static void sendInt (int data) {
fTxUart -- .sendByte (data >>> 8);
fTxUart -- .sendByte (data & 0x00FF);
}
/**
* Utility method to receive 2 bytes and make an
* int value (16 bits in Javelin) from them.
**/
static int receiveInt () {
int byte1 = fRxUart -- .receiveByte ();
int byte2 = fRxUart -- .receiveByte ();
return byte2 | (byte1 << 8);
}
/**
* Utility method to receive an int value and compare it to the password.
**/
static void checkPW () {
do {
int data = receiveInt ();
if (data == fPassword -- ) {
fTxUart -- .sendString ( " PW OK! \ n \ r " );
break;
}
fTxUart -- .sendString ( " Wrong PW! \ n \ r " );
} while (true);
} // checkPW
} // class SendTempDataJavelin
The class TempDataGenJavelin creates an instance of the DS1620 class
from the package stamp.peripheral.sensor.temperature and passes
the numbers of the pins that connect to the chip. The getData() method provides
the temperature readings in units of 0.5 degrees Celsius. See Figure 23.1 for an
example of temperature readings from the chip.
import stamp.core.*;
import stamp.peripheral.sensor.temperature.DS1620;
/**
* Create a class that obtains the current temperature with the DS1620 chip.
*Itextends the DataGenerator class and overrides the getData() method to
Search WWH ::




Custom Search