I'm a newb and am having issues with an "if" statement.
I believe I have the programming correct. When I upload the sketch to the OLED it hangs up on the first IF statement and will not move on. If I take the IF questions out of the upload everything else displays properly. I do not have the WIF or FP sensors hooked up to the Uno, so there is no input, but that shouldn't matter, right?
I have read a the post that says- "Fill the data buffer with 0's prior to the read, or set the data[readlength] = 0; after the read." But, I have no idea what that means or how to do that.
Will one of you kind people please look at my sketch to make sure it is correct and tell me what I can do to fix the display issue.
Thanks,
Craig
#include "DHT.h"
#include <Adafruit_CharacterOLED.h>
Adafruit_CharacterOLED lcd(OLED_V2, 6, 7, 8, 9, 10, 11, 12);
const int WIFsensor = A4; // pin that the sensor is attached to
const int WIFledPin = 2; // pin that the LED is attached to
const int WIFthreshold = 1; // an arbitrary threshold level that's in the range of the analog input
const int FPsensor = A1; // pin that the sensor is attached to
const int FPledPin = 1; // pin that the LED is attached to
const int FPthreshold = 500; // an arbitrary threshold level that's in the range of the analog input
#define DHTPIN A3
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println("DHTxx test!");
pinMode(WIFledPin, OUTPUT);
pinMode(FPledPin, OUTPUT);
lcd.begin(16, 2);
dht.begin();
}
void loop() {
int h = dht.readHumidity();
// Read temperature as Celsius (the default)
int t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
int f = dht.readTemperature(true);
if (isnan(h) || isnan(t) || isnan(f)) {
return;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
//-----------------------------------------------------WIF
lcd.setCursor(0, 0);
lcd.print("H20 In Fuel? ");
// read the value of the WIF Sensor:
int WIFsensorValue = analogRead(WIFsensor);
//
// if the analog value is high enough, turn on the LED:
if (WIFsensorValue > WIFsensor) {
digitalWrite(WIFledPin, HIGH);
lcd.print ("YES");
} else {
digitalWrite(WIFledPin, LOW);
lcd.print ("NO");
delay(5000);
lcd.clear();
//-----------------------------------------------------Fuel Pressure
// read the value of the fuel pressure Sensor:
int FPsensorValue = analogRead(FPsensor);
if the analog value is high enough, turn on the LED:
if (FPsensorValue > FPsensor) {
digitalWrite(FPledPin, HIGH);
lcd.print ("YES");
} else {
digitalWrite(FPledPin, LOW);
lcd.print ("NO");
//----------------------------------------------------------------LCD print Humidity
lcd.setCursor(0, 0);
lcd.print("Humidity: ");
lcd.print(h);
lcd.print(" %\t");
//-----------------------------------------------------------------LCD print temperature
lcd.setCursor(0, 1);
lcd.print("Cab Temp: ");
lcd.print(f);
lcd.print(" F");
delay(5000);
lcd.clear();
//-----------------------------------------------------------------LCD print heat index
lcd.setCursor(0, 0);
lcd.print("Heat index:");
lcd.print(hif, 0);
lcd.print(" F");
//-----------------------------------------------------------------LCD print fuel pressure
lcd.setCursor(0, 1);
lcd.print("Fuel PSI:");
// lcd.print(hif,0);
delay(5000);
lcd.clear();
}
Air_Temp.ino.ino (3.03 KB)