Added the header files to for changing the arduino code to OOP
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
#include <WiFiMulti.h>
|
#include <WiFiMulti.h>
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <WebSocketsClient.h>
|
#include <WebSocketsClient.h>
|
||||||
|
#include <nodeCodeHeader.h>
|
||||||
|
|
||||||
// define pins on esp32
|
// define pins on esp32
|
||||||
#define MICPIN 6
|
#define MICPIN 6
|
||||||
|
14
arduino/node-code/node-code-final/nodeCodeFinal.ino
Normal file
14
arduino/node-code/node-code-final/nodeCodeFinal.ino
Normal 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();
|
||||||
|
}
|
54
arduino/node-code/node-code-final/nodeCodeHeader.cpp
Normal file
54
arduino/node-code/node-code-final/nodeCodeHeader.cpp
Normal 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;
|
||||||
|
}
|
16
arduino/node-code/node-code-final/nodeCodeHeader.h
Normal file
16
arduino/node-code/node-code-final/nodeCodeHeader.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef nodeReading_h
|
||||||
|
#define nodeReading_h
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
#
|
||||||
|
|
||||||
|
class nodeReadings() {
|
||||||
|
|
||||||
|
public:
|
||||||
|
nodeReadings();
|
||||||
|
void setup();
|
||||||
|
void resetValues();
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Reference in New Issue
Block a user