1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-21 15:54:39 +01:00

Modified Barometric Pressure Sensor to make it easier for beginners to understand.

This commit is contained in:
Tom Igoe 2010-08-15 13:32:38 +00:00
parent aab8563d1e
commit d58ea9b378

View File

@ -1,4 +1,3 @@
/*
SCP1000 Barometric Pressure Sensor Display
@ -30,7 +29,7 @@ by Tom Igoe
const int PRESSURE = 0x1F; //3 most significant bits of pressure
const int PRESSURE_LSB = 0x20; //16 least significant bits of pressure
const int TEMPERATURE = 0x21; //16 bit temperature reading
cont byte READ = 0b11111100; // SCP1000's read command
const byte READ = 0b11111100; // SCP1000's read command
const byte WRITE = 0b00000010; // SCP1000's write command
// pins used for the connection with the sensor
@ -89,13 +88,14 @@ void loop() {
unsigned int readRegister(byte thisRegister, int bytesToRead ) {
byte inByte = 0; // incoming byte from the SPI
unsigned int result = 0; // result to return
Serial.print(thisRegister, BIN);
Serial.print("\t");
// SCP1000 expects the register name in the upper 6 bits
// of the byte. So shift the bits left by two bits:
thisRegister = thisRegister << 2;
// now combine the address and the command into one byte
dataToSend = thisRegister & READ;
byte dataToSend = thisRegister & READ;
Serial.println(thisRegister, BIN);
// take the chip select low to select the device:
digitalWrite(chipSelectPin, LOW);
// send the device the register you want to read:
@ -129,7 +129,7 @@ void writeRegister(byte thisRegister, byte thisValue) {
// of the byte. So shift the bits left by two bits:
thisRegister = thisRegister << 2;
// now combine the register address and the command into one byte:
dataToSend = thisRegister | WRITE;
byte dataToSend = thisRegister | WRITE;
// take the chip select low to select the device:
digitalWrite(chipSelectPin, LOW);
@ -140,3 +140,4 @@ void writeRegister(byte thisRegister, byte thisValue) {
// take the chip select high to de-select:
digitalWrite(chipSelectPin, HIGH);
}