seperate stuff to functions, cleanup

This commit is contained in:
Marcus 2024-03-31 05:53:57 +02:00
parent c3e6e8dd9e
commit d7f92f57ba

View file

@ -74,21 +74,6 @@ const unsigned char* bmpallArray[1] = {
bmpCanGrow_Logo bmpCanGrow_Logo
}; };
// I2C moisture sensor measurements
// soil moisture value
int chirpMoisture;
int chirpMoistureOld = 0 ;
// temp value from i2c sensor
int chirpTemp;
int chirpTempOld = 0;
// light intensity value
int chirpLight;
int chirpLightOld = 0;
// DHT measurements
float dhtTemp;
float dhtHumidity;
DHT dht(PINdht, DHTTYPE); DHT dht(PINdht, DHTTYPE);
void writeI2CRegister8bit(int addr, int value) { void writeI2CRegister8bit(int addr, int value) {
@ -180,6 +165,13 @@ int getSoilmoisture() {
return soilmoisture; return soilmoisture;
} }
int getLightchirp() {
// get the "light value" from I2C chirp module
writeI2CRegister8bit(0x20, 3); //request light measurement
int lightchirp = readI2CRegister16bit(0x20, 4);
return lightchirp;
}
void setup() { void setup() {
// setup pins // setup pins
pinMode(PINfan, OUTPUT); pinMode(PINfan, OUTPUT);
@ -225,43 +217,14 @@ void setup() {
} }
void loop() { void loop() {
chirpMoisture = readI2CRegister16bit(0x20, 0); // set display cursor to top left
/*
* Test for refresh one value. Test read i2c values
Serial.print(readI2CRegister16bit(0x20, 0)); //read capacitance register
Serial.print(", ");
Serial.print(readI2CRegister16bit(0x20, 5)); //temperature register
Serial.print(", ");
writeI2CRegister8bit(0x20, 3); //request light measurement
Serial.println(readI2CRegister16bit(0x20, 4)); //read light register
display.setCursor(0,0);
display.print("Capacitance: ");
display.setCursor(73,0);
display.setTextColor(SSD1306_BLACK);
display.print(chirpMoistureOld);
display.display();
display.setCursor(73,0);
display.setTextColor(SSD1306_WHITE);
display.println(chirpMoisture);
float chirpMoistureF = chirpMoisture / 10;
display.print(chirpMoisture);
chirpMoistureOld = chirpMoisture;
*/
display.setCursor(0,0); display.setCursor(0,0);
// display text
display.print("I2C: "); display.print("I2C: ");
display.print(getSoilmoisture()); display.print(getSoilmoisture());
display.print(", "); display.print(", ");
display.println(getTemperature(1)); display.println(getTemperature(1));
/* display.print(", ");
writeI2CRegister8bit(0x20, 3); //request light measurement
display.println(readI2CRegister16bit(0x20, 4)); */
display.print("DHT11: "); display.print("DHT11: ");
display.print(getTemperature(0)); display.print(getTemperature(0));
@ -270,10 +233,13 @@ void loop() {
display.display(); display.display();
display.print(":) Water: "); display.print("Water Status: ");
display.println(getWaterlevel()); display.println(getWaterlevel());
display.print("light: ");
display.println(getLightchirp());
// print everything on the display
display.display(); display.display();
delay(800); delay(800);