ok. so i got the non blocking dht22 and non blocking ds182bo working together,
what a pain,
just wondering if anyone sees a way to make it more clean ,
please ignore anything that doesent have to do with this
/*Grow tent brain,
project started march 2018
people who helped along the way
arduino.cc
- odometer
-sherzaad
*
#include <Button.h>
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#include <dht_nonblocking.h>
#include "RTClib.h"
#include <Wire.h>
#include <LiquidCrystal.h>
DS3231 rtc;
#include <OneWire.h>
#include <Arduino.h>
#include "nonBlockingDS18B20.h"
enum machineStates {
IDLE, WAITING_FOR_CONVERSION, ABORTED
};
const uint8_t ONE_WIRE_BUS = 12; // Change this to Pin # connected to OneWire bus
const uint8_t RESOLUTION = 9;
const unsigned long maxWaitTime = 5000;
const unsigned long interMeasurementPeriod = 1000;
machineStates currentState;
unsigned long measurementStartTime, measurementStopTime;
unsigned long interMeasurementTimer;
OneWire oneWire(ONE_WIRE_BUS);
nonBlockingDS18B20 tempSensors(&oneWire);
uint8_t numDS18;
static const int DHT_SENSOR_PIN = 13; //DHT22 pin number here
#define DHT_SENSOR_TYPE DHT_TYPE_22 //other pin infor for libraries
DHT_nonblocking dht_sensor( DHT_SENSOR_PIN, DHT_SENSOR_TYPE );
////////////////////////////////////////////////////////////////////////////////////////////////////////////Setup//////////////////////////////////////////////////////////
void setup() {
Serial.begin(9600);
Wire.begin();
rtc.begin();
button1.begin();
button2.begin();
button3.begin();
button4.begin();
button5.begin();
button6.begin();
button7.begin();
button8.begin();
pixels.begin();
pixels.setBrightness(pixelbright);
rtc.adjust(DateTime(__DATE__, __TIME__));
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
}
uint8_t index;
DeviceAddress addr;
// Locate and Enumerate the DS18xx-type Temperature Sensors
numDS18 = tempSensors.begin(RESOLUTION);
//set
}
//Set DHT22 nnblocking
static bool measure_environment( float *temperature, float *humidity )
{
static unsigned long measurement_timestamp = millis( );
/* Measure once every four seconds. */
if( millis( ) - measurement_timestamp > 4000ul )
{
if( dht_sensor.measure( temperature, humidity ) == true )
{
measurement_timestamp = millis( );
return( true );
}
}
return( false );
}
/////////////////////////////////////////////////////////////////////////////////////////Loop/////////////////////////////////////////////////////////////////////////
void loop() {
float temperature;
float humidity;
float tempC1 = tempSensors.getLatestTempC(0);
float tempC2 = tempSensors.getLatestTempC(1);
unsigned long currentMillis;
static uint32_t loopCount = 0;
currentMillis = millis();
switch (currentState) {
case WAITING_FOR_CONVERSION:
if ((tempSensors.isConversionDone()) && ( measure_environment( &temperature, &humidity ) == true )) {
measurementStopTime = currentMillis;
Serial.print(tempC1);
Serial.println(F(" (C), "));
Serial.print(tempC2);
Serial.println(F(" (C), "));
//Temp&humid
Serial.print( temperature);
Serial.println( " (C), " );
Serial.print( );
Serial.println( " (%) " );
Serial.println();
/* Measure temperature and humidity. If the functions returns
true, then a measurement is available. */
//time
DateTime now = rtc.now();
char buf[100];
strncpy(buf, "DD.MM.YYYY hh:mm:ss\0", 100);
Serial.println(now.format(buf));
Serial.println();
currentState = IDLE;
interMeasurementTimer = currentMillis;
}
break;
case IDLE:
// Check if it's time to start another measurement
if (currentMillis - interMeasurementTimer >= interMeasurementPeriod) {
currentState = WAITING_FOR_CONVERSION;
loopCount = 0;
// Kick off another set of non-blocking sensor readings
measurementStartTime = currentMillis;
if (!tempSensors.startConvertion()) {
Serial.println(F("Failed to Start Conversion Cycle, Aborting"));
currentState = ABORTED;
}
}
break;
case ABORTED:
break;
}