I PIN data, latch e clock servono perché ho utilizzato uno shift register per interfacciarmi
con dei led
#include
#include
#define I2C_ADDRESS 0x76
BMx280I2C bmx280(I2C_ADDRESS);
const int clockp = 8;
const int latchp = 9;
const int datap = 10;
void setup() {
Serial.begin(9600);
Wire.begin();
pinMode (datap, OUTPUT);
pinMode (latchp, OUTPUT);
pinMode (clockp, OUTPUT);
pinMode (3, OUTPUT);
pinMode (6, OUTPUT);
digitalWrite (3, HIGH);
digitalWrite (6, HIGH);
bmx280.begin();
bmx280.resetToDefaults();
bmx280.writeOversamplingPressure(BMx280MI::OSRS_P_x16);
bmx280.writeOversamplingTemperature(BMx280MI::OSRS_T_x16);
}
void loop() {
bmx280.measure();
do {
delay(100);
} while (!bmx280.hasValue());
float temperatura = bmx280.getTemperature();
Serial.println ("temperatura");
Serial.println (temperatura);
float pressione = bmx280.getPressure();
Serial.println ("pressione");
Serial.println (pressione);
delay(100);
if (temperatura <= 18 and pressione <= 97700) {
digitalWrite(latchp, LOW);
shiftOut(datap, clockp, MSBFIRST, 0x13);
digitalWrite (latchp, HIGH);
}
if (temperatura <= 18 and pressione >= 97701) {
digitalWrite(latchp, LOW);
shiftOut(datap, clockp, MSBFIRST, 0x0c);
digitalWrite (latchp, HIGH);
}
if (temperatura >= 18.1 and temperatura <= 25 and pressione <= 97700) {
digitalWrite(latchp, LOW);
shiftOut(datap, clockp, MSBFIRST, 0x12);
digitalWrite (latchp, HIGH);
}
if (temperatura >= 18.1 and temperatura <= 25 and pressione >= 97701) {
digitalWrite(latchp, LOW);
shiftOut(datap, clockp, MSBFIRST, 0x0a);
digitalWrite (latchp, HIGH);
}
if (temperatura >= 25.1 and pressione <= 97700) {
digitalWrite(latchp, LOW);
shiftOut(datap, clockp, MSBFIRST, 0x11);
digitalWrite (latchp, HIGH);
}
if (temperatura >= 25.1 and pressione >= 97701) {
digitalWrite(latchp, LOW);
shiftOut(datap, clockp, MSBFIRST, 0x09);
digitalWrite (latchp, HIGH);
}
delay(1000);
}