#include "DHT.h"
/*
AVCS-DHT1 DIY Temperature & Humidity USB Sensor Sketch v1
- used in AVCS SENS profile for VoiceAttack
- by SemlerPDX Mar/Apr 2022 CC BY-SA 4.0
- VETERANS-GAMING.COM/AVCS
--This AVCS-DHT1 Sketch is using the Adafruit "DHT.h" Library above, credits:
==================================================================================
Copyright (c) 2020 Adafruit Industries
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.
==================================================================================
*/
// IF you are using any other pin, ensure it is defined here, and of the same type pin as Uno/Micro Pin#2
#define DHTPIN 5
// IF you are using a DHT22, change the value here to define & use this type of sensor
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600); // Define speed at 9600 baud, do not change this value
Serial.write('q');
Serial.write('\n');
// while (!Serial) {
// ; // wait for serial port to connect. Needed for native USB
// }
dht.begin();
}
#define SLOWED 1323
void slower(void) {
for (volatile uint32_t count = SLOWED; count > 0; count--);
}
#define WRONG_VAL 35
#define RIGHT_VAL 34
void loop() {
float h = dht.readHumidity() + 9;//Add calculated offset for radiant case heat
float t = dht.readTemperature() - 2.25;//Subtract calcuated offset for radiant case heat
float f = ((t * 9) / 5) + 32;//Calculate °F ourselves, since we've changed t (°C) above
if (isnan(h) || isnan(t) || isnan(f)) {
return;
}
float x = dht.computeHeatIndex(f, h);
// AVCS SENS profile may allow senor arrays in future, this is DHT#1
// Serial Data Output must be in the following format:
// [AVCS,tt.tt,hh.hh,ff.ff,xx.xx,DHT1]
String dataPrints = "";
dataPrints.concat("[AVCS,");
dataPrints.concat(t);
dataPrints.concat(",");
dataPrints.concat(h);
dataPrints.concat(",");
dataPrints.concat(f);
dataPrints.concat(",");
dataPrints.concat(x);
dataPrints.concat(",DHT1]");
for (int chars = 0; chars <=
// RIGHT_VAL
WRONG_VAL
; chars++) {
// Serial.write('p');
char ch = dataPrints.charAt(chars); // junk char last position is what?
if (
ch == '\0'
) { Serial.println("\n junk was a null\n");
}
Serial.write(dataPrints.charAt(chars));
for (volatile int p = 11; p > 0; p--) { slower(); }
}
Serial.write('\n');
//Serial.flush(); ?? Is this needed? Doesn't seem to matter either way...
}