C++ forbids comparison

I get this error when I try to compile a sketch for an esp8266 12e. This sketch complied with an Uno.

ISO C++ forbids comparison between pointer and integer [-fpermissive]

f ((now.hour() == OnHour1) && (now.minute() == OnMin1) && (now.day() == OnDay1) && (now.month() == OnMonth1)) {
    digitalWrite (relay1, LOW);
    lcd.setCursor(1, 2);
    lcd.print("ON");
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address Ox3F (Check yours)
RTC_DS1307 rtc;    // Create a RealTimeClock object (I set the time in another sketch)
/*-----( Declare Variables )-----*/
dht DHT;
#define DHT11_PIN 4 // use pin to sample data from DHT module
const int relay1 = 2; //Digital pin that the Relay is connected
const int relay2 = 5; //Digital pin that the Relay is connected
const int relay3 = 6; //Digital pin that the Relay is connected

const int OnMin1 = 46;
const int OnHour1[]= {17,18,19,20};//Array multi hour
const int OnDay1 = 16;
const int OnMonth1 = 12;
const int OnYear1 = 2017;
const int OffMin1 = 47;
const int OffHour1 = 17;
const int OffDay1 = 16;
const int OffMonth1 = 12;
const int OffYear1 = 2017;

const int OnMin2 = 42;
const int OnHour2 = 17;
const int OnDay2 = 16;
const int OnMonth2 = 12;
const int OnYear2 = 2017;
const int OffMin2 = 43;
const int OffHour2 = 17;
const int OffDay2 = 16;
const int OffMonth2 = 12;
const int OffYear2 = 2017;

const int OnMin3 = 17;
const int OnHour3 = 16;
const int OnDay3 = 16;
const int OnMonth3 = 17;
const int OnYear3 = 2017;
const int OffMin3 = 17;
const int OffHour3 = 16;
const int OffDay3 = 16;
const int OffMonth3 = 17;
const int OffYear3 = 2017;

void setup()
{
  Serial.begin(9600);
  Serial.println("DHT TEST PROGRAM ");
  Serial.print("DHT LIBRARY VERSION: ");
  Serial.println(DHT_LIB_VERSION);
  Serial.println();
  Serial.println("Humidity % \tTemperature (C) \tTime \tDate");
  lcd.begin(20, 4); // defines it is a 20 character four line display
  rtc.begin(); // Start the RTC library code
}

void loop()
{
  // READ DATA
  DateTime now = rtc.now();
  int chk = DHT.read11(DHT11_PIN);
  Serial.print(DHT.humidity, 1);
  Serial.print(",\t");
  Serial.print("\t");
  Serial.print(DHT.temperature, 1);
  Serial.print(",\t");
  Serial.print("\t");
  Serial.print("\t");
  Serial.print(now.hour(), DEC);
  Serial.print(':');
  Serial.print(now.minute(), DEC);
  Serial.print(':');
  Serial.print(now.second(), DEC);
  Serial.print(' ');
  Serial.print(now.day(), DEC);
  Serial.print('/');
  Serial.print(now.month(), DEC);
  Serial.print('/');
  Serial.println(now.year(), DEC);
  lcd.setCursor(0, 0); // start postion of Humidity text on LCD
  lcd.print(DHT.humidity, 0); // 0 creates whole number, 1 two decimal
  lcd.print("% Humidity ");
  lcd.setCursor(14, 0); // start postion of temperature text on LCD
  lcd.print(DHT.temperature * 1.8 + 32, 0); //Farhenheit conversion
  lcd.setCursor(17, 0);
  lcd.print("F");
  lcd.setCursor(0, 1); // start postion of time text on LCD
  lcd.print(now.hour(), DEC);
  lcd.print(':');
  lcd.print(now.minute(), DEC);
  lcd.print('.');
  lcd.print(now.second(), DEC);
  lcd.print('.');
  lcd.print(now.year(), DEC);
  lcd.print('/');
  lcd.print(now.month(), DEC);
  lcd.print('/');
  lcd.print(now.day(), DEC);
  lcd.print(' ');
  lcd.setCursor(0, 3); // start postion of time text on LCD
  lcd.print("ZONE-1 " "ZONE-2 "  "ZONE-3");

  delay(1000); // screen - sample & LCD refresh time 1 second although DHT say min 2 seconds but works ok.

  if ((now.hour() == OnHour1) && (now.minute() == OnMin1) && (now.day() == OnDay1) && (now.month() == OnMonth1)) {
    digitalWrite (relay1, LOW);
    lcd.setCursor(1, 2);
    lcd.print("ON");

  }
  else if ((now.hour() == OffHour1) && (now.minute() == OffMin1) && (now.day() == OffDay1) && (now.month() == OffMonth1)) {
    digitalWrite (relay1, HIGH);
    lcd.setCursor(1, 2);
    lcd.print("OFF");

  }

  if ((now.hour() == OnHour2) && (now.minute() == OnMin2) && (now.day() == OnDay2) && (now.month() == OnMonth2)) {
    digitalWrite (relay2, LOW);
    lcd.setCursor(8, 2);
    lcd.print("ON");
  }
  else if ((now.hour() == OffHour2) && (now.minute() == OffMin2) && (now.day() == OffDay2) && (now.month() == OffMonth2)) {
    digitalWrite (relay2, HIGH);
    lcd.setCursor(8, 2);
    lcd.print("OFF");
  }

  if ((now.hour() == OnHour3) && (now.minute() == OnMin3) && (now.day() == OnDay3) && (now.month() == OnMonth3)) {
    digitalWrite (relay3, LOW);
    lcd.setCursor(15, 2);
    lcd.print("ON");
  }
  else if ((now.hour() == OffHour3) && (now.minute() == OffMin3) && (now.day() == OffDay3) && (now.month() == OffMonth3)) {
    digitalWrite (relay3, HIGH);
    lcd.setCursor(15, 2);
    lcd.print("OFF");
  }
}

//
// END OF FILE

Since OnHour1 is an array of int, the compiler is correctly pointing out that you can't compare it with a single int that now.hour() returns.

wildbill:
Since OnHour1 is an array of int, the compiler is correctly pointing out that you can't compare it with a single int that now.hour() returns.
[/quo#

define OnMonth1 (12); Like this

wildbill:
Since OnHour1 is an array of int, the compiler is correctly pointing out that you can't compare it with a single int that now.hour() returns.

Essentially you need to index your array to get a single integer value so that the comparison compiles.

E.G.

(now.hour() == OnHour1[0])

boylesg:
Essentially you need to index your array to get a single integer value so that the comparison compiles.

E.G.

(now.hour() == OnHour1[0])

All the if statements would have to have the exact hour and mins and seconds. The format is wrong. Do I have that right

That will sort it out, or at least let it compile. What was your intent in having four on hours though? Was it supposed to switch the relay at each of them?

9000 character limit. Hummm. two post for this one

This first code works with an esp8266 12-e When I put it together with the main code (see next post)

// RTC and LCD use i2c port (i2c Gnd 5V and pins a4 sda, a5 scl) DHT-11 BRICK unit uses Gnd 5V and pin 4
// Released to the public domain
//
/*-----( Import needed libraries )-----*/
#include <Wire.h>              // In standard library
//#include <dht.h>               // https://arduino-info.wikispaces.com/TemperatureHumidity
#include <LiquidCrystal_I2C.h> // https://arduino-info.wikispaces.com/LCD-Blue-I2C
#include "RTClib.h"            // https://arduino-info.wikispaces.com/DS1307_RealTime_Clock_Brick
/*-----( Declare Constants )-----*/

/*-----( Declare objects )-----*/
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address Ox3F (Check yours)
RTC_DS1307 rtc;    // Create a RealTimeClock object (I set the time in another sketch)
/*-----( Declare Variables )-----*/
//dht DHT;
#define DHT11_PIN 4 // use pin to sample data from DHT module
const int relay1 = 2; //Digital pin that the Relay is connected
const int relay2 = 5; //Digital pin that the Relay is connected
const int relay3 = 6; //Digital pin that the Relay is connected

byte OnMin1 = 4;
byte OnHour1 = 3;  //[]= {17,18,19,20};//Array multi hour
byte OnDay1 = 2;
byte OnMonth1 = 5;
byte OnYear1 = 4;
byte OffMin1 = 47;
byte OffHour1 = 17;
byte OffDay1  = 16;
byte OffMonth1 = 12;
byte OffYear1  = 2017;

byte OnMin2 = 42;
byte OnHour2 = 17;
byte OnDay2 = 16;
byte OnMonth2 = 12;
byte OnYear2 = 2017;
byte OffMin2 = 43;
byte OffHour2 = 17;
byte OffDay2 = 16;
byte OffMonth2 = 12;
byte OffYear2 = 2017;

byte OnMin3 = 17;
byte OnHour3 = 16;
byte OnDay3 = 16;
byte OnMonth3 = 17;
byte OnYear3 = 2017;
byte OffMin3 = 17;
byte OffHour3 = 16;
byte OffDay3 = 16;
byte OffMonth3 = 17;
byte OffYear3 = 2017;

void setup()
{
  Serial.begin(9600);
  //Serial.println("DHT TEST PROGRAM ");
  //Serial.print("DHT LIBRARY VERSION: ");
  //Serial.println(DHT_LIB_VERSION);
  Serial.println();
  //Serial.println("Humidity % \tTemperature (C) \tTime \tDate");
  lcd.begin(20, 4); // defines it is a 20 character four line display
  rtc.begin(); // Start the RTC library code
}

void loop()
{
  // READ DATA
  DateTime now = rtc.now();
  //int chk = DHT.read11(DHT11_PIN);
  //Serial.print(DHT.humidity, 1);
  Serial.print(",\t");
  Serial.print("\t");
  //Serial.print(DHT.temperature, 1);
  Serial.print(",\t");
  Serial.print("\t");
  Serial.print("\t");
  Serial.print(now.hour(), DEC);
  Serial.print(':');
  Serial.print(now.minute(), DEC);
  Serial.print(':');
  Serial.print(now.second(), DEC);
  Serial.print(' ');
  Serial.print(now.day(), DEC);
  Serial.print('/');
  Serial.print(now.month(), DEC);
  Serial.print('/');
  Serial.println(now.year(), DEC);
  lcd.setCursor(0, 0); // start postion of Humidity text on LCD
  //lcd.print(DHT.humidity, 0); // 0 creates whole number, 1 two decimal
  lcd.print("% Humidity ");
  lcd.setCursor(14, 0); // start postion of temperature text on LCD
  //lcd.print(DHT.temperature * 1.8 + 32, 0); //Farhenheit conversion
  lcd.setCursor(17, 0);
  lcd.print("F");
  lcd.setCursor(0, 1); // start postion of time text on LCD
  lcd.print(now.hour(), DEC);
  lcd.print(':');
  lcd.print(now.minute(), DEC);
  lcd.print('.');
  lcd.print(now.second(), DEC);
  lcd.print('.');
  lcd.print(now.year(), DEC);
  lcd.print('/');
  lcd.print(now.month(), DEC);
  lcd.print('/');
  lcd.print(now.day(), DEC);
  lcd.print(' ');
  lcd.setCursor(0, 3); // start postion of time text on LCD
  lcd.print("ZONE-1 " "ZONE-2 "  "ZONE-3");

  //if (now.hour() == (22) && now.minute() == (39) && now.second == (4));
  //(now.hour() == OnHour1[0])

  delay(1000); // screen - sample & LCD refresh time 1 second although DHT say min 2 seconds but works ok.

  if ((now.hour() == OnHour1) && (now.minute() == OnMin1) && (now.day() == OnDay1) && (now.month() == OnMonth1)) {
    digitalWrite (relay1, LOW);
    lcd.setCursor(1, 2);
    lcd.print("ON");

  }
  else if ((now.hour() == OffHour1) && (now.minute() == OffMin1) && (now.day() == OffDay1) && (now.month() == OffMonth1)) {
    digitalWrite (relay1, HIGH);
    lcd.setCursor(1, 2);
    lcd.print("OFF");

  }

  if ((now.hour() == OnHour2) && (now.minute() == OnMin2) && (now.day() == OnDay2) && (now.month() == OnMonth2)) {
  digitalWrite (relay2, LOW);
  lcd.setCursor(8, 2);
  lcd.print("ON");
}
else if ((now.hour() == OffHour2) && (now.minute() == OffMin2) && (now.day() == OffDay2) && (now.month() == OffMonth2)) {
  digitalWrite (relay2, HIGH);
  lcd.setCursor(8, 2);
  lcd.print("OFF");
}

if ((now.hour() == OnHour3) && (now.minute() == OnMin3) && (now.day() == OnDay3) && (now.month() == OnMonth3)) {
  digitalWrite (relay3, LOW);
  lcd.setCursor(15, 2);
  lcd.print("ON");
}
else if ((now.hour() == OffHour3) && (now.minute() == OffMin3) && (now.day() == OffDay3) && (now.month() == OffMonth3)) {
  digitalWrite (relay3, HIGH);
  lcd.setCursor(15, 2);
  lcd.print("OFF");
}
}

//
// END OF FILE
//

sprinkfitter:
9000 character limit. Hummm. two post for this one

No, post it as an attachment.

I get the error OnHour1 was not declared in this scope. I want to control relays by sec min hour day week month. Why does one complied and the other one does not.

/*-----( Import needed libraries for Oled )-----*/
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SPITFT.h>
#include <Adafruit_SPITFT_Macros.h>
#include <gfxfont.h>
#include "Adafruit_MCP23017.h"
#include <SPI.h>
#include <DHT.h>
#include <DHT_U.h>
#include <Wire.h>
#include "RTClib.h"
#include "DHT.h"
#define DHTPIN 2     // what digital pin we're connected to
#define DHTTYPE DHT11   // DHT 22  (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);
#define OLED_RESET 0
Adafruit_MCP23017 mcp;
Adafruit_SSD1306 display(OLED_RESET);
#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
/*-----( Import needed libraries for RTC )-----*/
/*-----( Declare Constants and Pin Numbers )-----*/
// Not needed: RTC Lib expects connections as above

/*-----( Declare objects )-----*/
RTC_DS1307 rtc;    // Create a RealTimeClock object

/*-----( Declare Variables )-----*/
// NONE because the library handles this...

void setup()   /****** SETUP: RUNS ONCE ******/
{
  mcp.begin(); 0x20;    // use default address 0
  Serial.begin(9600);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x64)
  dht.begin();
  display.display();
  delay(2000);
  Wire.begin();
  rtc.begin(); // Start the RTC library code
  mcp.pinMode(0, OUTPUT);
  mcp.pinMode(1, OUTPUT);
  mcp.pinMode(2, OUTPUT);
  mcp.pinMode(3, OUTPUT);

  /*----( SET the date and time.  Comment OUT these lines after setting )----*/
  // Put these "//" in front of the line you do NOT want to use
  // following line sets the RTC to the date & time this sketch was compiled
  rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  // This line sets the RTC with an explicit date & time, for example to set
  // May 21, 2015 at 6pm you would call: (use 24 hour time)
  //rtc.adjust(DateTime(2018, 1, 2, 15, 17, 0));
  
  byte OnMin1 = 4;
  byte OnHour1 = 3;  //[]= {17,18,19,20};//Array multi hour
  byte OnDay1 = 2;
  byte OnMonth1 = 5;
  byte OnYear1 = 4;
  byte OffMin1 = 47;
  byte OffHour1 = 17;
  byte OffDay1  = 16;
  byte OffMonth1 = 12;
  byte OffYear1  = 2017;

  byte OnMin2 = 42;
  byte OnHour2 = 17;
  byte OnDay2 = 16;
  byte OnMonth2 = 12;
  byte OnYear2 = 2017;
  byte OffMin2 = 43;
  byte OffHour2 = 17;
  byte OffDay2 = 16;
  byte OffMonth2 = 12;
  byte OffYear2 = 2017;

  byte OnMin3 = 17;
  byte OnHour3 = 16;
  byte OnDay3 = 16;
  byte OnMonth3 = 17;
  byte OnYear3 = 2017;
  byte OffMin3 = 17;
  byte OffHour3 = 16;
  byte OffDay3 = 16;
  byte OffMonth3 = 17;
  byte OffYear3 = 2017;

}//--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  DateTime now = rtc.now();  // Read data from the RTC Chip

  display.clearDisplay();
  // text display tests
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(4, 0);
  display.print(now.year(), DEC); //
  display.print('*');
  display.print(now.month(), DEC);
  display.print('*');
  display.print(now.day(), DEC);
  display.print('*');
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(10, 16);
  display.print(now.hour(), DEC);
  display.print(':');
  display.print(now.minute(), DEC);
  display.print(':');
  display.print(now.second(), DEC);
  display.println();
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0, 32);
  display.println("Z1- Z2- Z3");
  display.display();
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    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);
  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(hic);
  Serial.print(" *C ");
  Serial.print(hif);
  Serial.println(" *F");
  delay(5000);

  Serial.print(now.year(), DEC); //
  Serial.print('-');
  Serial.print(now.month(), DEC);
  Serial.print('-');
  Serial.print(now.day(), DEC);
  Serial.print('  ');
  Serial.print(now.hour(), DEC);
  Serial.print(':');
  Serial.print(now.minute(), DEC);
  Serial.print(':');
  Serial.print(now.second(), DEC);
  Serial.println();

  delay(1000);
  if ((now.hour() == OnHour1) && (now.minute() == OnMin1) && (now.day() == OnDay1) && (now.month() == OnMonth1)) {
    mcp.digitalWrite(1, HIGH);
    lcd.setCursor(1, 2);
    lcd.print("ON");

  }
  else if ((now.hour() == OffHour1) && (now.minute() == OffMin1) && (now.day() == OffDay1) && (now.month() == OffMonth1)) {
    mcp.digitalWrite(1, LOW);
    lcd.setCursor(1, 2);
    lcd.print("OFF");

  }

  if ((now.hour() == OnHour2) && (now.minute() == OnMin2) && (now.day() == OnDay2) && (now.month() == OnMonth2)) {
    mcp.digitalWrite(1, HIGH);
    lcd.setCursor(8, 2);
    lcd.print("ON");
  }
  else if ((now.hour() == OffHour2) && (now.minute() == OffMin2) && (now.day() == OffDay2) && (now.month() == OffMonth2)) {
    mcp.digitalWrite(1, LOW);
    lcd.setCursor(8, 2);
    lcd.print("OFF");
  }

  if ((now.hour() == OnHour3) && (now.minute() == OnMin3) && (now.day() == OnDay3) && (now.month() == OnMonth3)) {
    mcp.digitalWrite(1, HIGH);
    lcd.setCursor(15, 2);
    lcd.print("ON");
  }
  else if ((now.hour() == OffHour3) && (now.minute() == OffMin3) && (now.day() == OffDay3) && (now.month() == OffMonth3)) {
    mcp.digitalWrite(1, LOW);
    lcd.setCursor(15, 2);
    lcd.print("OFF");



  }//--(end main loop )---

  /*-----( Declare User-written Functions )-----*/
  //NONE

  //*********( THE END )***********

Do you know what scope is?

aarg:
Do you know what scope is?

Let me look it up

sprinkfitter:
All the if statements would have to have the exact hour and mins and seconds. The format is wrong. Do I have that right

If you intention was to compare now.hour() to all the elements in your array named OnHour1 and find the first one that matches now.hour() then I suggest you do so in a function like this:

int8_t compare(uint8_t nHourNow, uint8_t *pOnHour1, const uint8_t nSizeOnHour1)
{
    int8_t nI = 0;
    for (nI = 0; nI < nSizeOnHour1; nI++)
    {
         if (pOnHour1[nI] == nHourNow)
             break; //Out of the for loop
    }
    if (nI > nSizeOnHour1)
        nI = -1;
    return nI;
}
.
.
.
.

if ((compare(now.hour(), OnHour1, sizeof OnHour1) > -1) && ...........

sprinkfitter:
Let me look it up

I did not know that... There is a lot thinks I do not know about programming. I was on a roll LOL

Variables in the C programming language, which Arduino uses, have a property called scope. This is in contrast to early versions of languages such as BASIC where every variable is a global variable.

A global variable is one that can be seen by every function in a program. Local variables are only visible to the function in which they are declared. In the Arduino environment, any variable declared outside of a function (e.g. setup(), loop(), etc. ), is a global variable.

When programs start to get larger and more complex, local variables are a useful way to insure that only one function has access to its own variables. This prevents programming errors when one function inadvertently modifies variables used by another function.

It is also sometimes handy to declare and initialize a variable inside a for loop. This creates a variable that can only be accessed from inside the for-loop brackets.

I guess I need to know how to do that??

sprinkfitter:
I did not know that... There is a lot thinks I do not know about programming. I was on a roll LOL

Variables in the C programming language, which Arduino uses, have a property called scope. This is in contrast to early versions of languages such as BASIC where every variable is a global variable.

A global variable is one that can be seen by every function in a program. Local variables are only visible to the function in which they are declared. In the Arduino environment, any variable declared outside of a function (e.g. setup(), loop(), etc. ), is a global variable.

When programs start to get larger and more complex, local variables are a useful way to insure that only one function has access to its own variables. This prevents programming errors when one function inadvertently modifies variables used by another function.

It is also sometimes handy to declare and initialize a variable inside a for loop. This creates a variable that can only be accessed from inside the for-loop brackets.

I guess I need to know how to do that??

Just keep coding matey - you will get the hang of it and eventually be an expert.

It just takes time, lots or practice, lots of reading and lots of questions in here.

And the hungrier you are to learn the faster you will learn!

Getting back to your error, where is OnHour1 declared and where is it referenced (used)? Hint - what scope is it in?

I can tell you from experience that, once you have a good grasp of one of the earlier languages like C (or Pascal), it makes it far easier to pick up other languages like javascript, PHP, ASP, CSS, HTML, python, C# etc

Because on the whole the language syntax is quite similar in many of them.

And if not you have still re-wired your brain to intuitively 'get' the syntax and logic in a short period of time.

aarg:
Getting back to your error, where is OnHour1 declared and where is it referenced (used)? Hint - what scope is it in?

Making them a global variable. Putting them before the setup.