mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-17 22:23:10 +03:00
Modified Barometric Pressure Sensor to make it easier for beginners to understand.
This commit is contained in:
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
SCP1000 Barometric Pressure Sensor Display
|
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 = 0x1F; //3 most significant bits of pressure
|
||||||
const int PRESSURE_LSB = 0x20; //16 least significant bits of pressure
|
const int PRESSURE_LSB = 0x20; //16 least significant bits of pressure
|
||||||
const int TEMPERATURE = 0x21; //16 bit temperature reading
|
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
|
const byte WRITE = 0b00000010; // SCP1000's write command
|
||||||
|
|
||||||
// pins used for the connection with the sensor
|
// pins used for the connection with the sensor
|
||||||
@ -89,13 +88,14 @@ void loop() {
|
|||||||
unsigned int readRegister(byte thisRegister, int bytesToRead ) {
|
unsigned int readRegister(byte thisRegister, int bytesToRead ) {
|
||||||
byte inByte = 0; // incoming byte from the SPI
|
byte inByte = 0; // incoming byte from the SPI
|
||||||
unsigned int result = 0; // result to return
|
unsigned int result = 0; // result to return
|
||||||
|
Serial.print(thisRegister, BIN);
|
||||||
|
Serial.print("\t");
|
||||||
// SCP1000 expects the register name in the upper 6 bits
|
// SCP1000 expects the register name in the upper 6 bits
|
||||||
// of the byte. So shift the bits left by two bits:
|
// of the byte. So shift the bits left by two bits:
|
||||||
thisRegister = thisRegister << 2;
|
thisRegister = thisRegister << 2;
|
||||||
// now combine the address and the command into one byte
|
// 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:
|
// take the chip select low to select the device:
|
||||||
digitalWrite(chipSelectPin, LOW);
|
digitalWrite(chipSelectPin, LOW);
|
||||||
// send the device the register you want to read:
|
// 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:
|
// of the byte. So shift the bits left by two bits:
|
||||||
thisRegister = thisRegister << 2;
|
thisRegister = thisRegister << 2;
|
||||||
// now combine the register address and the command into one byte:
|
// 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:
|
// take the chip select low to select the device:
|
||||||
digitalWrite(chipSelectPin, LOW);
|
digitalWrite(chipSelectPin, LOW);
|
||||||
@ -140,3 +140,4 @@ void writeRegister(byte thisRegister, byte thisValue) {
|
|||||||
// take the chip select high to de-select:
|
// take the chip select high to de-select:
|
||||||
digitalWrite(chipSelectPin, HIGH);
|
digitalWrite(chipSelectPin, HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user