Added the header files to for changing the arduino code to OOP

This commit is contained in:
Dano van den Bosch
2024-03-13 15:47:42 +01:00
parent 25de52c54b
commit c4880ce0e2
4 changed files with 85 additions and 0 deletions

View File

@@ -6,6 +6,7 @@
#include <WiFiMulti.h>
#include <WiFi.h>
#include <WebSocketsClient.h>
#include <nodeCodeHeader.h>
// define pins on esp32
#define MICPIN 6

View File

@@ -0,0 +1,14 @@
#include <nodeCodeHeader.h>
nodeReadings esp32Node();
void setup() {
// put your setup code here, to run once:
esp32Node.setup();
}
void loop() {
// put your main code here, to run repeatedly:
esp32Node.loop();
}

View File

@@ -0,0 +1,54 @@
#include "arduino.h"
#include "nodeCodeHeader.h"
nodeReadings::nodeReadings() {
}
void nodeReadings::setup(){
// make serial connection at 115200 baud
Serial.begin(115200);
// tell display what settings to use
display.begin(i2c_adress, true);
display.clearDisplay();
// tell sensors to start reading
dht.begin();
sgp.begin();
pinMode(MICPIN, INPUT);
pinMode(DHTPIN, INPUT);
websocketSetup();
resetValues();
}
void nodeReadings::loop() {
// loop the websocket connection so it stays alive
webSocket.loop();
// update when interval is met
if (currentMillis - lastMillis >= interval){
lastMillis = millis();
update();
}
// update the counter
currentMillis = millis();
}
void nodeReadings::resetValues() {
counter = 0;
eCO2 = 0;
TVOC = 0;
temperature = 0;
humidity = 0;
currentMillis = 0;
lastMillis = 0;
errorSGP30 = false;
errorDHT11 = false;
noise = false;
}

View File

@@ -0,0 +1,16 @@
#ifndef nodeReading_h
#define nodeReading_h
#include "Arduino.h"
#
class nodeReadings() {
public:
nodeReadings();
void setup();
void resetValues();
private:
};
#endif