Merge branch 'main' into 'Website_websocket'
# Conflicts: # arduino/node-code/node-code-final/node-code-final.ino # web/classes.js # web/index.html # web/main.js # web/styles.css
This commit is contained in:
40
arduino/Button code/simple-buttons.ino
Normal file
40
arduino/Button code/simple-buttons.ino
Normal file
@@ -0,0 +1,40 @@
|
||||
//connect the 3v3 directly to the button and the other end of the button to a pin.
|
||||
//this script adds a digital resistor so you dont have to add one yourself
|
||||
|
||||
const int buttonPin = 21; // the number of the pushbutton pin
|
||||
const int buttonPin1 = 1; // the number of the pushbutton pin
|
||||
const int buttonPin2 = 37; // the number of the pushbutton pin
|
||||
|
||||
|
||||
// variables will change:
|
||||
int buttonState = 0; // variable for reading the pushbutton status
|
||||
int buttonState1 = 0; // variable for reading the pushbutton status
|
||||
int buttonState2 = 0; // variable for reading the pushbutton status
|
||||
|
||||
void setup() {
|
||||
// initialize the pushbutton pin as an input:
|
||||
pinMode(buttonPin, INPUT_PULLDOWN);
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the state of the pushbutton value:
|
||||
buttonState = digitalRead(buttonPin);
|
||||
buttonState1 = digitalRead(buttonPin1);
|
||||
buttonState2 = digitalRead(buttonPin2);
|
||||
|
||||
|
||||
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
|
||||
if (buttonState == HIGH) {
|
||||
Serial.println("ik ben high");
|
||||
}
|
||||
else if (buttonState1 == HIGH){
|
||||
Serial.println("ik ben higher");
|
||||
}
|
||||
else if (buttonState2 == HIGH){
|
||||
Serial.println("ik ben highest");
|
||||
}
|
||||
else {
|
||||
// turn LED off:
|
||||
}
|
||||
}
|
69
arduino/Screen code/Screen-code-full/Screen-code-full.ino
Normal file
69
arduino/Screen code/Screen-code-full/Screen-code-full.ino
Normal file
@@ -0,0 +1,69 @@
|
||||
#include <SPI.h>
|
||||
#include "Adafruit_GFX.h"
|
||||
#include "Adafruit_ST7796S_kbv.h"
|
||||
#include "headerFile.h"
|
||||
#include "displayText.h"
|
||||
int i = 0;
|
||||
|
||||
char* Question[] = {
|
||||
"How clean are the toilets?",
|
||||
"How clean is the study area?",
|
||||
"What do you think of the temperature in the study area?",
|
||||
"How crowded would you say the study area is?",
|
||||
"Is there enough help available?"
|
||||
};
|
||||
|
||||
char* Answer[] = {
|
||||
"clean, normal, disgusting",
|
||||
"clean, normal, disgusting",
|
||||
"hot, perfect, cold",
|
||||
"not at all, its fine, really crowded",
|
||||
"no, decently, yes"
|
||||
};
|
||||
|
||||
//simplify the name of the library
|
||||
Adafruit_ST7796S_kbv tft = Adafruit_ST7796S_kbv(TFT_CS, TFT_DC, MOSI, SCK, TFT_RST, MISO);
|
||||
DisplayText displayText(tft);
|
||||
|
||||
|
||||
void setup() {
|
||||
tft.begin(); // Initialize the display
|
||||
tft.setRotation(3); // Set the rotation to horizontal
|
||||
tft.fillScreen(ST7796S_BLACK);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
i++;
|
||||
if (i == 5) {
|
||||
i = 0;
|
||||
}
|
||||
|
||||
tft.fillScreen(ST7796S_BLACK); // Fill the screen with black color
|
||||
// writeText(Question[0], 2, 50, 0, 0);
|
||||
// writeText(Answer[0], 2, 50, 300, 4000);
|
||||
displayText.writeText(Question[i], 3, 0, 0, 0, true);
|
||||
displayText.writeText(Answer[i], 3, 0, 200, 0, true);
|
||||
delay(10000);
|
||||
}
|
||||
|
||||
|
||||
// void writeText(char* text, int size, int posX, int posY, int screenTime, bool center){
|
||||
// //if true overwrites x
|
||||
// if (center){
|
||||
// posX = centerText(text);
|
||||
// }
|
||||
// tft.setCursor(posX, posY); // Set the cursor to the top left corner
|
||||
// tft.setTextSize(size); // Set textsize
|
||||
// tft.println(text);
|
||||
// delay(screenTime);
|
||||
// }
|
||||
|
||||
// int centerText(char* text) {
|
||||
// int16_t x1, y1;
|
||||
// uint16_t w, h;
|
||||
|
||||
// tft.getTextBounds(text, 0, 0, &x1, &y1, &w, &h); // Calculate the width of the text
|
||||
// int x = (tft.width() - w) / 2; // Calculate the x-coordinate for the centered text
|
||||
|
||||
// return x;
|
||||
// }
|
25
arduino/Screen code/Screen-code-full/displayText.cpp
Normal file
25
arduino/Screen code/Screen-code-full/displayText.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "displayText.h"
|
||||
#include "Arduino.h"
|
||||
|
||||
//constructor
|
||||
DisplayText::DisplayText(Adafruit_ST7796S_kbv& tftDisplay) : tft(tftDisplay) {
|
||||
|
||||
}
|
||||
|
||||
void DisplayText::writeText(char* text, int size, int posX, int posY, int screenTime, bool center) {
|
||||
if (center) {
|
||||
posX = centerText(text);
|
||||
}
|
||||
tft.setCursor(posX, posY);
|
||||
tft.setTextSize(size);
|
||||
tft.println(text);
|
||||
delay(screenTime);
|
||||
}
|
||||
|
||||
int DisplayText::centerText(char* text) {
|
||||
int16_t x1, y1;
|
||||
uint16_t w, h;
|
||||
tft.getTextBounds(text, 0, 0, &x1, &y1, &w, &h);
|
||||
int x = (tft.width() - w) / 2;
|
||||
return x;
|
||||
}
|
17
arduino/Screen code/Screen-code-full/displayText.h
Normal file
17
arduino/Screen code/Screen-code-full/displayText.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef DISPLAYTEXT_H
|
||||
#define DISPLAYTEXT_H
|
||||
|
||||
#include "Adafruit_GFX.h"
|
||||
#include "Adafruit_ST7796S_kbv.h"
|
||||
|
||||
class DisplayText {
|
||||
private:
|
||||
Adafruit_ST7796S_kbv& tft;
|
||||
int centerText(char* text);
|
||||
|
||||
public:
|
||||
DisplayText(Adafruit_ST7796S_kbv& tftDisplay);
|
||||
void writeText(char* text, int size, int posX, int posY, int screenTime, bool center);
|
||||
};
|
||||
|
||||
#endif
|
6
arduino/Screen code/Screen-code-full/headerFile.h
Normal file
6
arduino/Screen code/Screen-code-full/headerFile.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#define TFT_CS 14
|
||||
#define TFT_DC 13
|
||||
#define TFT_RST 12
|
||||
#define MOSI 11
|
||||
#define SCK 10
|
||||
#define MISO 9
|
53
arduino/Screen code/screen-with-questions-nostyling.ino
Normal file
53
arduino/Screen code/screen-with-questions-nostyling.ino
Normal file
@@ -0,0 +1,53 @@
|
||||
//styling still needs to be done.
|
||||
//this code is to display the questions on the screen.
|
||||
#include <SPI.h>
|
||||
#include "Adafruit_GFX.h"
|
||||
#include "Adafruit_ST7796S_kbv.h"
|
||||
|
||||
#define TFT_CS 14
|
||||
#define TFT_DC 13
|
||||
#define TFT_RST 12
|
||||
#define MOSI 11
|
||||
#define SCK 10
|
||||
#define MISO 9
|
||||
|
||||
char* Question[] = {
|
||||
"How clean are the toilets? (clean, normal, disgusting).",
|
||||
"How clean is the study area? (clean, normal, disgusting).",
|
||||
"What do you think of the temperature in the study area? (hot, perfect, cold).",
|
||||
"How crowded would you say the study area is?(not at all, its fine, really crowded).",
|
||||
"Is there enough help available? (no, decently, yes)"
|
||||
};
|
||||
|
||||
//simplify the name of the library
|
||||
|
||||
Adafruit_ST7796S_kbv tft = Adafruit_ST7796S_kbv(TFT_CS, TFT_DC, MOSI, SCK, TFT_RST, MISO);
|
||||
|
||||
|
||||
|
||||
void setup() {
|
||||
tft.begin(); // Initialize the display
|
||||
tft.setRotation(3); // Set the rotation to horizontal
|
||||
tft.fillScreen(ST7796S_BLACK); // Fill the screen with black color
|
||||
tft.setTextColor(ST7796S_WHITE); // Set the text color to white
|
||||
tft.setTextSize(2); // Set the text size to 2
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
tft.setTextSize(2); // Set textsize
|
||||
tft.setCursor(0, 0); // Set the cursor to the top left corner
|
||||
//the cursor is where it types the text or shape on the screen, 0,0 is the topleft
|
||||
tft.println("Hello, world!"); // Print the text
|
||||
delay(2000); // Wait for 2 seconds
|
||||
|
||||
tft.fillScreen(ST7796S_BLACK); // Clear the screen
|
||||
|
||||
tft.setCursor(0, 0); // Set the cursor to the top left corner
|
||||
tft.println("New text!"); // Print the new text
|
||||
delay(2000); // Wait for 2 seconds
|
||||
tft.fillScreen(ST7796S_BLACK); // Clear the screen
|
||||
tft.setCursor(0, 0); // Set the cursor to the top left corner
|
||||
tft.println(Question[1]);
|
||||
delay(10000); //delay set a longer delay so the long text can write out
|
||||
}
|
40
arduino/Screen code/writetext function.ino
Normal file
40
arduino/Screen code/writetext function.ino
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <SPI.h>
|
||||
#include "Adafruit_GFX.h"
|
||||
#include "Adafruit_ST7796S_kbv.h"
|
||||
#include "headerFile.h"
|
||||
|
||||
char* Question[] = {
|
||||
"How clean are the toilets? (clean, normal, disgusting).",
|
||||
"How clean is the study area? (clean, normal, disgusting).",
|
||||
"What do you think of the temperature in the study area? (hot, perfect, cold).",
|
||||
"How crowded would you say the study area is?(not at all, its fine, really crowded).",
|
||||
"Is there enough help available? (no, decently, yes)"
|
||||
};
|
||||
|
||||
//simplify the name of the library
|
||||
Adafruit_ST7796S_kbv tft = Adafruit_ST7796S_kbv(TFT_CS, TFT_DC, MOSI, SCK, TFT_RST, MISO);
|
||||
|
||||
|
||||
|
||||
void setup() {
|
||||
tft.begin(); // Initialize the display
|
||||
tft.setRotation(3); // Set the rotation to horizontal
|
||||
tft.fillScreen(ST7796S_BLACK);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
writeText(Question[0], 2, 0, 0, 4000);
|
||||
writeText(Question[1], 2, 0, 0, 4000);
|
||||
writeText(Question[2], 2, 0, 0, 4000);
|
||||
}
|
||||
|
||||
|
||||
void writeText(char* text, int size, int posX, int posY, int screenTime){
|
||||
tft.fillScreen(ST7796S_BLACK); // Fill the screen with black color
|
||||
|
||||
tft.setCursor(posX, posY); // Set the cursor to the top left corner
|
||||
tft.setTextSize(size); // Set textsize
|
||||
tft.println(text);
|
||||
delay(screenTime);
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
// Sietse Jonker & Dano van den Bosch
|
||||
// 27/02/2024
|
||||
// Sietse Jonker & Dano Bosch
|
||||
// 28/02/2024
|
||||
|
||||
// include these libraries
|
||||
#include <Wire.h>
|
||||
@@ -21,6 +21,9 @@
|
||||
#define i2c_adress 0x3c
|
||||
#define USE_SERIAL Serial
|
||||
|
||||
// define node identification number
|
||||
#define nodeIdentificationNumber 1
|
||||
|
||||
// make new objects
|
||||
Adafruit_SH1106G display = Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire);
|
||||
DHT dht(DHTPIN, DHTTYPE);
|
||||
@@ -69,13 +72,13 @@ void webSocketEvent(WStype_t type, uint8_t * payload, size_t length) {
|
||||
webSocket.sendTXT("Connected");
|
||||
break;
|
||||
case WStype_TEXT:
|
||||
USE_SERIAL.printf("[WSc] get text: %s\n", payload);
|
||||
// USE_SERIAL.printf("[WSc] get text: %s\n", payload);
|
||||
|
||||
// send message to server
|
||||
// webSocket.sendTXT("message here");
|
||||
break;
|
||||
case WStype_BIN:
|
||||
USE_SERIAL.printf("[WSc] get binary length: %u\n", length);
|
||||
// USE_SERIAL.printf("[WSc] get binary length: %u\n", length);
|
||||
hexdump(payload, length);
|
||||
|
||||
// send data to server
|
||||
@@ -128,38 +131,38 @@ bool checkForError(){
|
||||
if (!sgp.IAQmeasure()) {
|
||||
Serial.println("SGP30: BAD");
|
||||
errorSGP30 = true;
|
||||
return true;
|
||||
} else {
|
||||
Serial.println("SGP30: OK");
|
||||
errorSGP30 = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isnan(temperature) || isnan(humidity)){
|
||||
Serial.println("DHT11: BAD");
|
||||
errorDHT11 = true;
|
||||
return true;
|
||||
} else {
|
||||
Serial.println("DHT11: OK");
|
||||
errorDHT11 = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// function to update when interval is met (see intervalCounter variable)
|
||||
void update(){
|
||||
// webSocket.sendTXT("{\"Temp\":\"" + String(temperature) + \",\"Humi\":\" " + String(humidity) + "\",\"eCO2\":\"" + String(sgp.eCO2) + "\",\"TVOC\":\"" + String(sgp.TVOC) + "\"}");
|
||||
webSocket.sendTXT("{\"Temp\":\"" + String(temperature) + "\",\"Humi\":\"" + String(humidity) + "\",\"eCO2\":\"" + String(sgp.eCO2) + "\",\"TVOC\":\"" + String(sgp.TVOC) + "\"}");
|
||||
// webSocket.sendTXT("Temp: " + String(temperature));
|
||||
// webSocket.sendTXT("Humi: " + String(humidity));
|
||||
// webSocket.sendTXT("eCO2: " + String(sgp.eCO2));
|
||||
// webSocket.sendTXT("TVOC: " + String(sgp.TVOC));
|
||||
// display sensordata on oled screen
|
||||
displayData();
|
||||
|
||||
// webSocket.sendTXT("{\"Temp\":\"" + String(temperature) + "\",\"Humi\":\"" + String(humidity) + "\",\"eCO2\":\"" + String(sgp.eCO2) + "\",\"TVOC\":\"" + String(sgp.TVOC) + "\"}");
|
||||
webSocket.sendTXT("{\"node\": \"" + String(nodeIdentificationNumber) + "\", \"Temp\":\"" + String(temperature) + "\",\"Humi\":\"" + String(humidity) + "\",\"eCO2\":\"" + String(sgp.eCO2) + "\",\"TVOC\":\"" + String(sgp.TVOC) + "\"}");
|
||||
|
||||
sgp.getIAQBaseline(&eCO2_base, &TVOC_base);
|
||||
|
||||
// read dht11 sensor
|
||||
temperature = float(dht.readTemperature());
|
||||
humidity = float(dht.readHumidity());
|
||||
|
||||
// check if any errors occured when reading sensors
|
||||
checkForError();
|
||||
}
|
||||
|
||||
// function to display data on oled screen
|
||||
@@ -177,12 +180,14 @@ void displayData() {
|
||||
+ "Humi: " + int(humidity) + "%" + '\n'
|
||||
+ "eCO2: " + int(sgp.eCO2) + '\n'
|
||||
+ "TVOC: " + int(sgp.TVOC));
|
||||
|
||||
|
||||
// display the screen
|
||||
display.display();
|
||||
}
|
||||
|
||||
// setup function
|
||||
void setup() {
|
||||
// make serial connection at 115200 baud
|
||||
Serial.begin(115200);
|
||||
|
||||
// tell display what settings to use
|
||||
@@ -191,8 +196,7 @@ void setup() {
|
||||
|
||||
// tell sensors to start reading
|
||||
dht.begin();
|
||||
sgp.begin();
|
||||
|
||||
sgp.begin();
|
||||
|
||||
pinMode(MICPIN, INPUT);
|
||||
pinMode(DHTPIN, INPUT);
|
||||
@@ -203,15 +207,9 @@ void setup() {
|
||||
|
||||
// loop function
|
||||
void loop() {
|
||||
// check for errors
|
||||
checkForError();
|
||||
|
||||
// loop the websocket connection so it stays alive
|
||||
webSocket.loop();
|
||||
|
||||
// display sensordata on oled screen
|
||||
displayData();
|
||||
|
||||
// update when interval is met
|
||||
if (currentMillis - lastMillis >= interval){
|
||||
lastMillis = millis();
|
||||
|
Reference in New Issue
Block a user