Need help cleaning up this program, I hope someone can assist.
#include <Adafruit_MLX90614.h>
#include <DistanceSensor.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "Adafruit_VL6180X.h"
#include <Wire.h>
#include <Adafruit_AMG88xx.h>
//#include <NHCSR04.h>
#include <afstandssensor.h>
#include <dht_nonblocking.h>
#define DHT_SENSOR_TYPE DHT_TYPE_11
static const int DHT_SENSOR_PIN = 2;
DHT_nonblocking dht_sensor(DHT_SENSOR_PIN, DHT_SENSOR_TYPE);
AfstandsSensor afstandssensor(13, 12); // Starter afstandssensoren på ben 13 og 12.
// Define pins
int baudrate = 9600;
const int echoPin = 12;
const int trigPin = 13;
//SR04 sensor(triggerPin, echoPin);
//double cm;
int val = 0;
const int buzzer = 9; //buzzer to arduino pin 9
float pixels[AMG88xx_PIXEL_ARRAY_SIZE];
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
Adafruit_VL6180X vl = Adafruit_VL6180X();
Adafruit_AMG88xx amg;
void setup() {
Serial.begin(9600);
pinMode(A0, INPUT);
pinMode(buzzer, OUTPUT); // Set buzzer - pin 9 as an output
}
static bool measure_environment(float *temperature, float *humidity) {
static unsigned long measurement_timestamp = millis();
/* Measure once every four seconds. */
if (millis() - measurement_timestamp > 3000ul) {
if (dht_sensor.measure(temperature, humidity) == true) {
measurement_timestamp = millis();
return (true);
}
}
}
//return (false);
while (!Serial)
;
Serial.println("Adafruit MLX90614 test");
if (!mlx.begin()) {
Serial.println("Error connecting to MLX sensor. Check wiring.");
while (1)
;
};
Serial.print("Emissivity = ");
Serial.println(mlx.readEmissivity());
Serial.println("================================================");
bool status;
// default settings
status = amg.begin();
if (!status) {
Serial.println("Could not find a valid AMG88xx sensor, check wiring!");
while (1)
;
}
Serial.println("Adafruit VL6180x test!");
if (!vl.begin()) {
Serial.println("Failed to find sensor");
while (1)
;
}
Serial.println("Sensor found!");
pinMode(3, INPUT); // LDR Sensor output pin connected
pinMode(4, OUTPUT); // LED PIN
}
}
void loop() {
/***********************************************************
This is a library example for the DHT11 Temp Sensor
***************************************************************/
float temperature;
float humidity;
Serial.print(temperature, 1);
/* Measure temperature and humidity. If the functions returns
true, then a measurement is available. */
if (measure_environment(&temperature, &humidity) == true)
if (temperature <= 30) {
Serial.println("it works");
Serial.print(temperature, 1);
}
delay(10);
/***************************************************************
Ultra Sonic HC-SR04 sensor and prints it to the serial port.
Get distance in cm
***************************************************************/
//Serial.println(afstandssensor.afstandCM());
int distance0 = 14.6;
int delta_distance = afstandssensor.afstandCM() - distance0;
// Måler afstanden for hver 500ms
Serial.println(afstandssensor.afstandCM());
if (afstandssensor.afstandCM() < 14.5) {
//Serial.println("Ultrasonic");
delay(10);
}
/***************************************************************
TOF continuous mode to take range measurements with the VL6180X.
The range readings are in units of mm.
***************************************************************/
float lux = vl.readLux(VL6180X_ALS_GAIN_5);
uint8_t range1 = vl.readRange();
float range0 = 113;
float deltarange = range1 - range0;
uint8_t status = vl.readRangeStatus();
if (status == VL6180X_ERROR_NONE) {
if (range1 < 106) {
delay(50);
//Serial.println("ICE TOF");
//Serial.println(range1);
//Serial.println();
/***************************************************************
AMG88xx GridEYE 8x8 IR camera.
Celsius Degrees
***************************************************************/
//read all the pixels
amg.readPixels(pixels);
//Serial.print("[");
for (int i = 1; i <= AMG88xx_PIXEL_ARRAY_SIZE; i++) {
//Serial.print(pixels[i - 1]);
//Serial.print(", ");
if (i % 8 == 0) //Serial.println();
//Serial.println("]");
//Serial.println();
if (pixels[i - 1] <= 0) {
//Serial.println("IR camera ICE found");
//delay a second
delay(50);
/***************************************************************
Photocell
***************************************************************/
{
val = digitalRead(3); // LDR Sensor output pin connected
//Serial.println(val); // see the value in serial mpnitor in Arduino IDE
delay(10);
if (val == 1) {
//Serial.println("***BLACK ICE***BLACK ICE***");
delay(10);
}
/***************************************************************
BUZZER
***************************************************************/
tone(buzzer, 1000); // Send 1KHz sound signal...
delay(1000); // ...for 1 sec
noTone(buzzer); // Stop sound...
delay(10); // ...for 1sec
}
} else {
//Serial.println("CLEAR");
delay(50);
}
}
}
}
}