#include 2 header files = type error

Hello,

I wrote one sketch including LiquidCrystal.h and a different sketch including Servo.h and they work great on their own, but when I combine the sketches into a new sketch and include both header files I get “type” errors for whatever header file was included second.

Any ideas? Thank you in advance!

Here is what I have tried:

I am using Arduino IDE (tried multiple different versions) with the Arduino Nano
I have used both <> and " " around the header file names
I have tried to use the IDE included libraries and have manually downloaded the zip and extracted within the sketch folder.
I have included the full path or just <Servo.h> and <LiquidCrystal.h>
I have modified both header files to #include the other header file
I copied one header file into the other, renamed it, and #included that file.

I am at my wits end. Is this an IDE issue? I am a noob to Arduino but have some experience with coding.

Here is an excerpt of the error message:

Error Message:

Arduino: 1.8.10 (Windows 10), Board: “Arduino Nano, ATmega328P”

C:\Users___\Documents\Arduino\Bahai_calendar\Bahai_calendar.ino: In function ‘void loop()’:

Bahai_calendar:281:13: error: ‘year’ was not declared in this scope

lcd.print(year);

Post the combined code you have now that doesn't work and the code that works with the "year" variable.

Clock - works.
Calendar - does not work for me. There may be other errors TBD in calendar but cant get past the header issue to see.

Bahai_calendar.ino (11.6 KB)

Bahai_clock.ino (10.6 KB)

This block of code:

  // initial Time display is 12:59:45 PM
  int mo = 1;
  int d = 1;
  int h = 17;
  int m = 0;
  int s = 0;
  int days_of_ha = 4;
  int ayyam = 0;
  int year = 176;
  int day_of_week = 1;
  int new_year = 1;

is in setup() and therefore only visible within setup().

I moved that code outside of setup and still have the same issue.

schmopke:
I moved that code outside of setup and still have the same issue.

There are many issues associated with having things inside setup() that should not be. Look at your list of errors (scroll through the whole list in the message window…)

Try this (1/2):

#include "Servo.h"
#include <LiquidCrystal.h>

/*
  ###
*/

Servo myday;  // create servo object to control a servo
Servo mymonth;
int day_pin = 8;
int month_pin = 11;

int step_angle = 0;

// This defines the LCD wiring to the DIGITALpins


// Digital LCD Constrast setting
int cs = 9; // pin 9 for contrast PWM
const int contrast = 100;// default contrast

// initial Time display is 12:59:45 PM
int mo = 1;
int d = 1;
int h = 17;
int m = 0;
int s = 0;
int days_of_ha = 4;
int ayyam = 0;
int year = 176;
int day_of_week = 1;
int new_year = 1;

// Time Set Buttons
int button1 = 0;
int button2 = 0;

// Pins definition for Time Set Buttons
int ms = 0; // pin 0 for Hours Setting
int ds = 1; // pin 1 for Minutes Setting

// Backlight Time Out
const int Time_light = 40;
int bl_TO = Time_light; // Backlight Time-Out
int bl = 10; // Backlight pin
const int backlight = 30; // no more then 7mA !!!

// For accurate Time reading, use Arduino Real Time Clock and not just delay()
static uint32_t last_time, now = 0; // RTC
// static uint32_t last_day_time, day_time = 0; // RTC

const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup()
{
    myday.attach(day_pin);
    mymonth.attach(month_pin);
  lcd.begin(16, 2);
  pinMode(ms, INPUT_PULLUP); // avoid external Pullup resistors for Button 1
  pinMode(ds, INPUT_PULLUP); // and Button 2
  analogWrite(cs, contrast); // Adjust Contrast VO
  analogWrite(bl, backlight); // Turn on Backlight
  pinMode(day_pin, OUTPUT);
  now = millis(); // read RTC initial value


  //  step_angle=6;
  //  myday.write(step_angle);

  //////////////////////////////////////////////////////
  // Set Baha'i Year
  for ( int i = 0 ; i < 16 ; i++) // make 5 time 250ms loop, for faster Button response    // inner 200ms loop
  {
    lcd.begin(16, 2); // every second
    // Update LCD Display
    lcd.setCursor(0, 0);
    lcd.print("Set Baha'i year: ");
    lcd.setCursor(0, 1); // for Line 2
    lcd.print(year);

    while ((now - last_time) < 250)   {
      now = millis();   //delay250ms
    }
    last_time = now;
    // read Setting Buttons
    button1 = digitalRead(ms);
    button2 = digitalRead(ds);

    //Backlight time out
    bl_TO--;    if (bl_TO == 0)
    { bl_TO++;             //
      analogWrite(bl, 0);
    }  // Backlight OFF

    // Hit any to activate Backlight
    if (  ((button1 == 0) | (button2 == 0)) & (bl_TO == 1)  )
    {
      bl_TO = Time_light;
      analogWrite(bl, backlight);
      // wait until Button released
      while ((button1 == 0) | (button2 == 0))
      {
        button1 = digitalRead(ms); // Read Buttons
        button2 = digitalRead(ds);
      }
    }
    else
      // Process Button 1 or Button 2 when hit while Backlight on
    {
      if (button1 == 0) {
        year--;
        i = 0;
        delay(150);
        bl_TO = Time_light;
        analogWrite(bl, backlight);
      }

      if (button2 == 0) {
        year++;
        i = 0;
        delay(150);
        bl_TO = Time_light;
        analogWrite(bl, backlight);
      }

    } // end if else
  }  // end for

  //////////////////////////////////////////////////////
  // Set day_of_week
  bl_TO = Time_light;
  for ( int i = 0 ; i < 16 ; i++) // make 5 time 250ms loop, for faster Button response    // inner 200ms loop
  {
    lcd.begin(16, 2); // every second
    // Update LCD Display
    lcd.setCursor(0, 0);
    lcd.print("Set Day of Week: ");
    lcd.setCursor(0, 1); // for Line 2
    lcd.print(day_of_week);
    lcd.print(" ");

    if (day_of_week == 1) lcd.print("Saturday");
    else if (day_of_week == 2) lcd.print("Sunday");
    else if (day_of_week == 3) lcd.print("Monday");
    else if (day_of_week == 4) lcd.print("Tuesday");
    else if (day_of_week == 5) lcd.print("Wednesday");
    else if (day_of_week == 6) lcd.print("Thursday");
    else if (day_of_week == 7) lcd.print("Friday");

    while ((now - last_time) < 250)   {
      now = millis();   //delay250ms
    }
    last_time = now;
    // read Setting Buttons
    button1 = digitalRead(ms);
    button2 = digitalRead(ds);

    //Backlight time out
    bl_TO--;    if (bl_TO == 0)
    { bl_TO++;             //
      analogWrite(bl, 0);
    }  // Backlight OFF

    // Hit any to activate Backlight
    if (  ((button1 == 0) | (button2 == 0)) & (bl_TO == 1)  )
    {
      bl_TO = Time_light;
      analogWrite(bl, backlight);
      // wait until Button released
      while ((button1 == 0) | (button2 == 0))
      {
        button1 = digitalRead(ms); // Read Buttons
        button2 = digitalRead(ds);
      }
    }
    else
      // Process Button 1 or Button 2 when hit while Backlight on
    {
      if (button1 == 0) {
        day_of_week--;
        if (day_of_week < 1) day_of_week = 7;
        i = 0;
        delay(150);
        bl_TO = Time_light;
        analogWrite(bl, backlight);
      }

      if (button2 == 0) {
        day_of_week++;
        if (day_of_week > 7) day_of_week = 1;
        i = 0;
        delay(150);
        bl_TO = Time_light;
        analogWrite(bl, backlight);
      }

    } // end if else
  }  // end for

  //////////////////////////////////////////////////////
  // Set Hour
  bl_TO = Time_light;
  for ( int i = 0 ; i < 16 ; i++) // make 5 time 250ms loop, for faster Button response    // inner 200ms loop
  {
    lcd.begin(16, 2); // every second
    // Update LCD Display
    lcd.setCursor(0, 0);
    lcd.print("Set Current hour: ");
    lcd.setCursor(0, 1); // for Line 2
    lcd.print(h);

    while ((now - last_time) < 250)   {
      now = millis();   //delay250ms
    }
    last_time = now;
    // read Setting Buttons
    button1 = digitalRead(ms);
    button2 = digitalRead(ds);

    //Backlight time out
    bl_TO--;    if (bl_TO == 0)
    { bl_TO++;             //
      analogWrite(bl, 0);
    }  // Backlight OFF

    // Hit any to activate Backlight
    if (  ((button1 == 0) | (button2 == 0)) & (bl_TO == 1)  )
    {
      bl_TO = Time_light;
      analogWrite(bl, backlight);
      // wait until Button released
      while ((button1 == 0) | (button2 == 0))
      {
        button1 = digitalRead(ms); // Read Buttons
        button2 = digitalRead(ds);
      }
    }
    else
      // Process Button 1 or Button 2 when hit while Backlight on
    {
      if (button1 == 0) {
        h--;
        i = 0;
        delay(150);
        bl_TO = Time_light;
        analogWrite(bl, backlight);
      }

      if (button2 == 0) {
        h++;
        i = 0;
        delay(150);
        bl_TO = Time_light;
        analogWrite(bl, backlight);
      }

    } // end if else
  }  // end for

}

.
.
.

2/2

/////////////////////////////////////////////////////
void loop()
{
  lcd.begin(16, 2); // every second
  // Update LCD Display
  lcd.setCursor(0, 0);
  // lcd.print("");
  lcd.print(year);
  lcd.print("/");
  lcd.print(mo);
  lcd.print("/");
  lcd.print(d);
  lcd.print("  ");
  if (h < 10)lcd.print("0");
  lcd.print(h);
  lcd.print(":");
  if (m < 10)lcd.print("0");
  lcd.print(m);

  lcd.setCursor(0, 1); // for Line 2
  if (mo == 1 && d == 1)         {
    lcd.print("Happy New Year! ");
    bl_TO = Time_light;
  }
  else if (d == 1)             {
    lcd.print("Happy Feast     ");
    bl_TO = Time_light;
  }
  else if (mo == 2 && d == 13)   {
    lcd.print("Happy 1st Ridván");
    bl_TO = Time_light;
  }
  else if (mo == 3 && d == 2)    {
    lcd.print("Happy 9th Ridván");
    bl_TO = Time_light;
  }
  else if (mo == 3 && d == 5)    {
    lcd.print("Happy 12 Ridván!");
    bl_TO = Time_light;
  }
  else if (mo == 4 && d == 8)    {
    lcd.print("Declaration Báb!");
    bl_TO = Time_light;
  }
  else if (mo == 4 && d == 13)   {
    lcd.print("Asc. Bahá'u'lláh");
    bl_TO = Time_light;
  }
  else if (mo == 6 && d == 17)   {
    lcd.print("Martyrdom of B");
    lcd.print((char)160);
    lcd.print("b");
    bl_TO = Time_light;
  }
  else if (mo == 14 && d == 4)   {
    lcd.print("Day of Covenant ");
    bl_TO = Time_light;
  }
  else if (mo == 14 && d == 6)   {
    lcd.print("Asc. Abdu'l-Bahá");
    bl_TO = Time_light;
  }
  else if (mo == 19 && d == 1)   {
    lcd.print("Happy Fasting!  ");
    bl_TO = Time_light;
  }
  else if (day_of_week == 1) lcd.print("Sa Jalal-Glory  ");
  else if (day_of_week == 2) lcd.print("Su Jamal-Beauty ");
  else if (day_of_week == 3) lcd.print("M Kamal-Perfection");
  else if (day_of_week == 4) lcd.print("Tu Fidal-Grace");
  else if (day_of_week == 5) lcd.print("W 'Idal-Justice");
  else if (day_of_week == 6) lcd.print("T Istijlal-Majesty");
  else if (day_of_week == 7) lcd.print("F Istiqlal-Independence");

  for ( int i = 0 ; i < 4 ; i++) // make 5 time 250ms loop, for faster Button response    // inner 200ms loop
  {
    while ((now - last_time) < 250)   {
      now = millis();   //delay250ms
    }
    last_time = now; // prepare for next loop

    // read Setting Buttons
    button1 = digitalRead(ms);
    button2 = digitalRead(ds);

    //Backlight time out
    bl_TO--;    if (bl_TO == 0)
    { bl_TO++;             //
      analogWrite(bl, 0);
    }  // Backlight OFF

    // Hit any to activate Backlight
    if (  ((button1 == 0) | (button2 == 0)) & (bl_TO == 1)  )
    {
      bl_TO = Time_light;
      analogWrite(bl, backlight);
      // wait until Button released
      while ((button1 == 0) | (button2 == 0))
      {
        button1 = digitalRead(ms); // Read Buttons
        button2 = digitalRead(ds);
      }
    }
    else
      // Process Button 1 or Button 2 when hit while Backlight on
    {
      if (button1 == 0) {
        mo++;
        if (mo >= 20) mo -= 19;
        delay(150);
        bl_TO = Time_light;
        analogWrite(bl, backlight);
      }

      if (button2 == 0) {
        d++;
        if (d >= 20) d -= 19;
        delay(150);
        bl_TO = Time_light;
        analogWrite(bl, backlight);
      }

    } // end if else
  }  // end for

  s++; //increment sec. counting

  if (s == 60) {
    s = 0;
    m++;
  }
  if (m == 60) {
    m = 0;
    h++;
  }
  if (h == 24) {
    h = 0; d++; day_of_week++; step_angle = 0;
    step_angle += 7;
    if (d == 5) {
      step_angle -= 2;
    }
    else if (d == 3 || d == 4 || d == 17 || d == 19) {
      step_angle -= 1;
    }
    else if (d == 2) {
      step_angle -= 3;
    }
    else if (d == 9 || d == 14) {
      step_angle += 1;
    }
    else if (d == 10 || d == 11 || d == 12 ) {
      step_angle += 2;
    }
    else if (d == 1) {
      step_angle += 3;
    }

    myday.write(step_angle);
  }

  if (d == 20) {
    d = 1; mo++;
    if (mo != 19)   {
      mymonth.write(180);
      delay(110);
      mymonth.write(90);
    }
  }

  if (mo == 18) new_year = 1;
  if (mo == 20) {
    mo = 1;
    d = 1;
    year++;
  }
  if (mo == 19 && new_year)
  {
    mymonth.write(180);
    delay(50);
    mymonth.write(90);

    ayyam = 1;
    d = 0;
    days_of_ha = 4;

    if (year == 178 || year == 182 || year == 187 || year == 191 ||
        year == 195 || year == 199 || year == 203 || year == 207 ||
        year == 211 || year == 216 || year == 220) days_of_ha = 5;

    while (ayyam)
    {
      new_year = 0;
      lcd.begin(16, 2); // every second
      // Update LCD Display
      lcd.setCursor(0, 0);
      lcd.print("Happy Ayyam-i-Ha!");
      lcd.setCursor(0, 1); // for Line 2
      lcd.print("Ha remaining: ");
      lcd.print(days_of_ha - d);

      for ( int i = 0 ; i < 4 ; i++) // make 5 time 250ms loop, for faster Button response    // inner 200ms loop
      {
        while ((now - last_time) < 250)   {
          now = millis();   //delay250ms
        }
        last_time = now; // prepare for next loop

        // read Setting Buttons
        button1 = digitalRead(ms);
        button2 = digitalRead(ds);

        //Backlight time out
        bl_TO--;    if (bl_TO == 0)
        { bl_TO++;             //
          analogWrite(bl, 0);
        }  // Backlight OFF

        // Hit any to activate Backlight
        if (  ((button1 == 0) | (button2 == 0)) & (bl_TO == 1)  )
        {
          bl_TO = Time_light;
          analogWrite(bl, backlight);
          // wait until Button released
          while ((button1 == 0) | (button2 == 0))
          {
            button1 = digitalRead(ms); // Read Buttons
            button2 = digitalRead(ds);
          }
        }
        else
          // Process Button 1 or Button 2 when hit while Backlight on
        {
          if (button1 == 0) {
            ayyam = 0;
            //   mo++;
            //   if (mo >= 20) mo -= 19;
            //   delay(150);
            bl_TO = Time_light;
            analogWrite(bl, backlight);
          }

          if (button2 == 0) {
            d++;
            if (d == days_of_ha) {
              ayyam = 0;
            }
            delay(150);
            bl_TO = Time_light;
            analogWrite(bl, backlight);
          }

        } // end if else

      } // for loop interval end
      s++; //increment sec. counting

      if (s == 60) {
        s = 0;
        m++;
      }
      if (m == 60) {
        m = 0;
        h++;
      }
      if (h == 24) {
        h = 0;
        d++;
        day_of_week++;
      }
      if (d == days_of_ha) {
        ayyam = 0;
      }



    } // while loop of Ha end
    mymonth.write(180);
    delay(50);
    mymonth.write(90);

    d = 1;

  } // month of Ha end

}  // void loop end