diff --git a/src/main copy.cpp.dis b/src/main copy.cpp.dis deleted file mode 100644 index 1b3b3fb..0000000 --- a/src/main copy.cpp.dis +++ /dev/null @@ -1,42 +0,0 @@ -#include - -const int lm35_pin = 34; /* LM35 O/P pin */ - -#define ADC_VREF_mV 3300.0 // in millivolt -#define ADC_RESOLUTION 4096.0 - -#define FILTER_LEN 15 - -uint32_t AN_Pot1_Buffer[FILTER_LEN] = {0}; - -float readADC_Avg(int pin) -{ - float avg = analogRead(pin); - for (int i = 0; i < 10; i++) - { - avg = (avg + analogRead(pin)) / 2; - delay(20); - } - return avg; -} - -void setup() -{ - Serial.begin(115200); - pinMode(lm35_pin, INPUT); - - analogSetClockDiv(255); -} - -void loop() -{ - float analogValue = readADC_Avg(lm35_pin); - float millivolts = analogValue * (ADC_VREF_mV / ADC_RESOLUTION) * 2; - // float millivolts = analogReadMilliVolts(lm35_pin); - float celsius = millivolts / 10; // 6.5 is the callibration offset measured using an oscilliscope - Serial.print("raw= "); - Serial.print(analogValue); - Serial.print(" in DegreeC= "); - Serial.println(celsius); - delay(1000); -} \ No newline at end of file diff --git a/src/realMainRenameLater.cpp b/src/main.cpp similarity index 100% rename from src/realMainRenameLater.cpp rename to src/main.cpp diff --git a/src/main.cpp.dis b/src/main.cpp.dis deleted file mode 100644 index 913e0c2..0000000 --- a/src/main.cpp.dis +++ /dev/null @@ -1,227 +0,0 @@ -// #include -// // #include -// #include -// #include - -// const char *ssid = "PET Aflytningsvogn #43"; -// const char *password = "zwr33htm"; - -// const char *mqtt_server = "192.168.24.215"; -// // const char *mqtt_server = "test.mosquitto.org"; - -// WiFiClient espClient; -// PubSubClient client(espClient); - -// const int lm35_pin = 34; /* LM35 O/P pin */ -// const int mic_pin = 35; -// const int light_pin = 32; -// const int motion_pin = 33; - -// #define ADC_VREF_mV 3300.0 // in millivolt -// #define ADC_RESOLUTION 4096.0 - -// #define FILTER_LEN 15 - -// float readADC_Avg(int pin) -// { -// float avg = analogRead(pin); -// for (int i = 0; i < 10; i++) -// { -// avg = (avg + analogRead(pin)) / 2; -// delay(20); -// } -// return avg; -// } - -// void setup_wifi() -// { -// delay(10); -// // We start by connecting to a WiFi network -// Serial.println(); -// Serial.print("Connecting to "); -// Serial.println(ssid); - -// WiFi.begin(ssid, password); - -// while (WiFi.status() != WL_CONNECTED) -// { -// delay(500); -// Serial.print("."); -// } - -// Serial.println(""); -// Serial.println("WiFi connected"); -// Serial.println("IP address: "); -// Serial.println(WiFi.localIP()); -// } - -// void reconnect() -// { -// // Loop until we're reconnected -// while (!client.connected()) -// { -// Serial.print("Attempting MQTT connection..."); -// // Attempt to connect -// if (client.connect("ESP8266Client")) -// { -// Serial.println("connected"); -// } -// else -// { -// Serial.print("failed, rc="); -// Serial.print(client.state()); -// Serial.println(" try again in 5 seconds"); -// // Wait 5 seconds before retrying -// delay(5000); -// } -// } -// } - -// void setup() -// { -// Serial.begin(115200); -// pinMode(lm35_pin, INPUT); -// pinMode(mic_pin, INPUT); -// pinMode(light_pin, INPUT); -// pinMode(motion_pin, INPUT); - -// pinMode(13, OUTPUT); -// digitalWrite(13, HIGH); - -// setup_wifi(); -// client.setServer(mqtt_server, 1883); -// } - -// #define SOUND_MEASURE_INTERVAL 1000 * 10 -// #define SOUND_HIGHEST_MEASURE_INTERVAL 200 -// #define TEMP_MEASURE_INTERVAL 1000 * 10 - -// unsigned long previousTemperatureMillis = 0; -// unsigned long previousSoundMillis = 0; -// unsigned long previousHighestSoundMillis = 0; - -// bool lastMotionState; - -// uint16_t highestSound = 0; -// uint16_t runningAverageSound = 0; - -// int j = 0; - -// void loop() -// { -// client.loop(); -// if (!client.connected()) -// { -// reconnect(); -// } -// j++; - -// unsigned long currentMillis = millis(); - -// if (currentMillis - previousTemperatureMillis >= TEMP_MEASURE_INTERVAL) -// { -// // save the last time you blinked the LED -// previousTemperatureMillis = currentMillis; - -// analogSetClockDiv(255); - -// float analogValueTemp = readADC_Avg(lm35_pin); -// float analogValueLight = readADC_Avg(light_pin); - -// analogSetClockDiv(1); - -// float millivolts = analogValueTemp * (ADC_VREF_mV / ADC_RESOLUTION) * 2; -// // float millivolts = analogReadMilliVolts(lm35_pin); -// float celsius = millivolts / 10; // 6.5 is the callibration offset measured using an oscilliscope -// Serial.print("raw= "); -// Serial.print(analogValueTemp); -// Serial.print(" in DegreeC= "); -// Serial.println(celsius); - -// DynamicJsonDocument docTemp(1024); - -// docTemp["device"] = "esp32-1"; -// docTemp["type"] = "temperature"; -// docTemp["value"] = celsius; - -// char bufferTemp[1024]; -// size_t bufferTempSize = serializeJson(docTemp, bufferTemp); -// client.publish("esp32/data", bufferTemp, bufferTempSize); - -// Serial.print("Light: "); -// Serial.println(analogValueLight); - -// DynamicJsonDocument docLight(1024); - -// docLight["device"] = "esp32-1"; -// docLight["type"] = "light"; -// docLight["value"] = analogValueLight; - -// char bufferLight[1024]; -// size_t bufferLightSize = serializeJson(docLight, bufferLight); -// client.publish("esp32/data", bufferLight, bufferLightSize); -// } - -// uint16_t soundValue = analogRead(mic_pin); - -// if (soundValue > highestSound) { -// highestSound = soundValue; -// } - -// if (currentMillis - previousHighestSoundMillis >= SOUND_HIGHEST_MEASURE_INTERVAL) -// { -// previousHighestSoundMillis = currentMillis; - -// if (runningAverageSound == 0) -// { -// runningAverageSound = highestSound; -// } -// else -// { -// runningAverageSound = (runningAverageSound + highestSound) / 2; -// } - -// highestSound = 0; -// } - -// if (currentMillis - previousSoundMillis >= SOUND_MEASURE_INTERVAL) -// { -// previousSoundMillis = currentMillis; - -// Serial.print(j); -// Serial.print(": sound: "); -// Serial.println(runningAverageSound); - -// DynamicJsonDocument doc(1024); - -// doc["device"] = "esp32-1"; -// doc["type"] = "sound"; -// doc["value"] = runningAverageSound; - -// char buffer[1024]; -// size_t n = serializeJson(doc, buffer); -// client.publish("esp32/data", buffer, n); - -// runningAverageSound = 0; -// j = 0; -// } - -// bool motionState = digitalRead(motion_pin); - -// if (lastMotionState != motionState) { -// Serial.print("Motionstate: "); -// Serial.println(motionState); - -// DynamicJsonDocument doc(1024); - -// doc["device"] = "esp32-1"; -// doc["type"] = "motion"; -// doc["value"] = motionState; - -// char buffer[1024]; -// size_t n = serializeJson(doc, buffer); -// client.publish("esp32/data", buffer, n); - -// lastMotionState = motionState; -// } -// } \ No newline at end of file diff --git a/src/mic.cpp.dis b/src/mic.cpp.dis deleted file mode 100644 index 0c91d6f..0000000 --- a/src/mic.cpp.dis +++ /dev/null @@ -1,84 +0,0 @@ -#include - -const int lm35_pin = 34; /* LM35 O/P pin */ -const int mic_pin = 35; - -void setup() -{ - Serial.begin(115200); - pinMode(lm35_pin, INPUT); - pinMode(mic_pin, INPUT); -} - -uint16_t highest = 0; -uint16_t highest2 = 0; -uint16_t runningAverage = 0; - -unsigned long previousSendMillis = 0; -unsigned long previousHighMillis = 0; - -#define MEASURE_INTERVAL 1000 * 10 - -int i = 0; - -void loop() -{ - uint16_t value = analogRead(mic_pin); - - if (value > highest) - { - highest = value; - } - - if (value > highest2) - { - highest2 = value; - } - - // if (value > 100) - // { - // if (runningAverage == 0) - // { - // runningAverage = value; - // } - // else - // { - // runningAverage = (runningAverage + value) / 2; - // } - // } - - i++; - - unsigned long currentMillis = millis(); - - if (currentMillis - previousHighMillis >= 200) - { - previousHighMillis = currentMillis; - - if (runningAverage == 0) - { - runningAverage = highest2; - } - else - { - runningAverage = (runningAverage + highest2) / 2; - } - - highest2 = 0; - } - - if (currentMillis - previousSendMillis >= MEASURE_INTERVAL) - { - previousSendMillis = currentMillis; - - Serial.print("average: "); - Serial.println(runningAverage); - runningAverage = 0; - - Serial.print(i); - Serial.print(": highest: "); - Serial.println(highest); - highest = 0; - i = 0; - } -} \ No newline at end of file