Add header file and refactor code
This commit is contained in:
40
arduino/node-code/node-code-final/headerFile.h
Normal file
40
arduino/node-code/node-code-final/headerFile.h
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
// include these libraries
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <Adafruit_SH110X.h>
|
||||||
|
#include <Adafruit_SGP30.h>
|
||||||
|
#include <DHT.h>
|
||||||
|
#include <WiFiMulti.h>
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <WebSocketsClient.h>
|
||||||
|
|
||||||
|
// define pins on esp32
|
||||||
|
#define MICPIN 6
|
||||||
|
#define DHTPIN 7
|
||||||
|
#define SCL 9
|
||||||
|
#define SDA 8
|
||||||
|
#define DHTTYPE DHT11
|
||||||
|
#define SCREEN_WIDTH 128
|
||||||
|
#define SCREEN_HEIGHT 64
|
||||||
|
#define i2c_adress 0x3c
|
||||||
|
#define USE_SERIAL Serial
|
||||||
|
|
||||||
|
// make new objects
|
||||||
|
Adafruit_SH1106G display = Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire);
|
||||||
|
DHT dht(DHTPIN, DHTTYPE);
|
||||||
|
WiFiMulti WiFiMulti;
|
||||||
|
Adafruit_SGP30 sgp;
|
||||||
|
WebSocketsClient webSocket;
|
||||||
|
|
||||||
|
// define variables
|
||||||
|
uint16_t TVOC_base, eCO2_base;
|
||||||
|
uint16_t counter = 0;
|
||||||
|
uint16_t eCO2 = 0;
|
||||||
|
uint16_t TVOC = 0;
|
||||||
|
uint16_t interval = 5000;
|
||||||
|
float temperature = 0;
|
||||||
|
float humidity = 0;
|
||||||
|
unsigned long currentMillis;
|
||||||
|
unsigned long lastMillis;
|
||||||
|
bool errorSGP30 = false;
|
||||||
|
bool errorDHT11 = false;
|
||||||
|
bool noise = false;
|
@@ -1,43 +1,5 @@
|
|||||||
// include these libraries
|
// include header file into code
|
||||||
#include <Wire.h>
|
#include <headerFile.h>
|
||||||
#include <Adafruit_SH110X.h>
|
|
||||||
#include <Adafruit_SGP30.h>
|
|
||||||
#include <DHT.h>
|
|
||||||
#include <WiFiMulti.h>
|
|
||||||
#include <WiFi.h>
|
|
||||||
#include <WebSocketsClient.h>
|
|
||||||
|
|
||||||
// define pins on esp32
|
|
||||||
#define MICPIN 6
|
|
||||||
#define DHTPIN 7
|
|
||||||
#define SCL 9
|
|
||||||
#define SDA 8
|
|
||||||
#define DHTTYPE DHT11
|
|
||||||
#define SCREEN_WIDTH 128
|
|
||||||
#define SCREEN_HEIGHT 64
|
|
||||||
#define i2c_adress 0x3c
|
|
||||||
#define USE_SERIAL Serial
|
|
||||||
|
|
||||||
// make new objects
|
|
||||||
Adafruit_SH1106G display = Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire);
|
|
||||||
DHT dht(DHTPIN, DHTTYPE);
|
|
||||||
WiFiMulti WiFiMulti;
|
|
||||||
Adafruit_SGP30 sgp;
|
|
||||||
WebSocketsClient webSocket;
|
|
||||||
|
|
||||||
// define variables
|
|
||||||
uint16_t TVOC_base, eCO2_base;
|
|
||||||
uint16_t counter = 0;
|
|
||||||
uint16_t eCO2 = 0;
|
|
||||||
uint16_t TVOC = 0;
|
|
||||||
uint16_t interval = 5000;
|
|
||||||
float temperature = 0;
|
|
||||||
float humidity = 0;
|
|
||||||
unsigned long currentMillis;
|
|
||||||
unsigned long lastMillis;
|
|
||||||
bool errorSGP30 = false;
|
|
||||||
bool errorDHT11 = false;
|
|
||||||
bool noise = false;
|
|
||||||
|
|
||||||
// setup function
|
// setup function
|
||||||
void setup() {
|
void setup() {
|
||||||
|
Reference in New Issue
Block a user