#include "headerFile.h" int i = 0; int questionID = 1; 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" }; Adafruit_ST7796S_kbv tft = Adafruit_ST7796S_kbv(TFT_CS, TFT_DC, MOSI, SCK, TFT_RST, MISO); DisplayText displayText(tft); void setup() { //buttonpins pinMode(16, INPUT_PULLDOWN); pinMode(17, INPUT_PULLDOWN); pinMode(18, INPUT_PULLDOWN); Serial.begin(9600); tft.begin(); // Initialize the display tft.setRotation(3); // Set the rotation to horizontal tft.fillScreen(ST7796S_BLACK); displayText.writeText("Loading...", 3, 0, 200, 0, true, true); websocketSetup(); } void loop() { webSocket.loop(); screenButtonHandler(); } void websocketSetup(){ WiFiMulti.addAP("iotroam", "BcgrFpX3kl"); WiFiMulti.addAP("ObsidianAmstelveen", "drijversstraatmaastricht"); while(WiFiMulti.run() != WL_CONNECTED) { delay(100); } // server address, port and URL webSocket.begin("145.92.8.114", 80, "/ws"); // try ever 500 again if connection has failed webSocket.setReconnectInterval(500); } void screenButtonHandler(){ int redButton = digitalRead(16); int whiteButton = digitalRead(17); int greenButton = digitalRead(18); if (initialized) { initialized = false; tft.fillScreen(ST7796S_BLACK); displayText.writeText(Question[i], 3, 0, 0, 0, true, false); displayText.writeText(Answer[i], 3, 0, 200, 0, true, true); } // 0 is best 2 is worst if (redButton == HIGH){ sendData(questionID, "0"); } if (whiteButton == HIGH){ sendData(questionID, "1"); } if (greenButton == HIGH){ sendData(questionID, "2"); } if (redButton || whiteButton || greenButton) { i++; questionID++; if (questionID == 6){ questionID = 1; } if (i == 5) { i = 0; } tft.fillScreen(ST7796S_BLACK); displayText.writeText(Question[i], 3, 0, 0, 0, true, false); displayText.writeText(Answer[i], 3, 0, 200, 0, true, true); } } void sendData(int question, String answer){ webSocket.sendTXT("{\"node\": \"" + String(WiFi.macAddress()) + "\", \"Response\":\"" + String(answer) + "\",\"QuestionID\":\"" + String(question) + "\"}"); } void hexdump(const void *mem, uint32_t len, uint8_t cols = 16) { const uint8_t* src = (const uint8_t*) mem; USE_SERIAL.printf("\n[HEXDUMP] Address: 0x%08X len: 0x%X (%d)", (ptrdiff_t)src, len, len); for(uint32_t i = 0; i < len; i++) { if(i % cols == 0) { USE_SERIAL.printf("\n[0x%08X] 0x%08X: ", (ptrdiff_t)src, i); } USE_SERIAL.printf("%02X ", *src); src++; } USE_SERIAL.printf("\n"); }