# Need Help Debugging LCD Display/Servo State Machine Code

**URL:** <https://forum.arduino.cc/t/need-help-debugging-lcd-display-servo-state-machine-code/512904>\
**Category:** Programming\
**Created:** [March 8, 2018, 10:56pm UTC](https://forum.arduino.cc/t/need-help-debugging-lcd-display-servo-state-machine-code/512904 "2018-03-08T22:56:38Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmp3mt](https://avatars.discourse-cdn.com/v4/letter/c/f6c823/32.png) [@cmp3mt](https://forum.arduino.cc/u/cmp3mt)\
**Post date:** [March 8, 2018, 10:56pm UTC](https://forum.arduino.cc/t/need-help-debugging-lcd-display-servo-state-machine-code/512904/1 "2018-03-08T22:56:38Z")

</div>

I'm trying to create a device that will use and lcd display to present a message once a light dependent resistor detects light and control a servo from the push of a button.

My code concerning the servo works just fine but I can't seem to get my lcd display to work. Here are my error messages:

sketch\_mar05a:71: error: 'lcd' does not name a type  
lcd.begin(16,2);  
^  
sketch\_mar05a:78: error: expected ';' at end of member declaration  
void Update()  
^  
sketch\_mar05a:80: error: 'ldrState' does not name a type  
ldrState = digitalRead(ldrPin); //read the digital state of ldrPin with digitalRead() function and store the value in ldrState variable  
^  
sketch\_mar05a:82: error: expected unqualified-id before '{' token  
{  
^  
sketch\_mar05a:163: error: expected '}' at end of input  
};  
^  
sketch\_mar05a:73: error: expected unqualified-id at end of input  
const int ldrPin = 7; // light dependent resistor pin  
^  
exit status 1  
'lcd' does not name a type

Here's my code:

```cpp
#include <Wire.h>
#include <Servo.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 16, 2);

class Twist
{
  const int servoPin = 9; // servo pin 
  Servo servo;              // the servo
  int pos = 0;  // variable to store the servo position
  int directionState = 0;
  int increment;        // increment to move for each interval
  int  updateInterval;      // interval between updates
  unsigned long lastUpdate; // last update of position

  const int buttonPin = 8; // pushbutton pin
int buttonState = 0;
 
public: 

  Twist(int interval)
  {
    updateInterval = interval;
    increment = 1;
  }

  
  void Attach(int pin)
  {
    servo.attach(9);
  }
  
  void Detach()
  {
    servo.detach();
  }
  
  void Update()
  {
    if((millis() - lastUpdate) > updateInterval)  // time to update
    {
      lastUpdate = millis();
      pos += increment;
  
  buttonState = digitalRead(buttonPin);
   
  if (directionState == 0) {
    if (buttonState == HIGH) {
      directionState = 1;
      for (pos = 20; pos < 180; pos = pos + 1) {
        servo.write(pos);
      }
    }
  } else if (directionState == 1) {
    if (buttonState == HIGH) {
      directionState = 0;
      for (pos = 180; pos > 1; pos = pos - 1) {
        servo.write(pos);
      }
    }
  }
 
    }
  }
};
 
Twist twist1(15);

class Display
{
lcd.begin(16,2);

const int ldrPin = 7;  // light dependent resistor pin
int ldrState; // local variable to hold ldr states

public:

void Update()

ldrState = digitalRead(ldrPin); //read the digital state of ldrPin with digitalRead() function and store the value in ldrState variable 

{
if (ldrState == HIGH)
{ 
  lcd.clear();
  lcd.setCursor(0,0); //Start at character 0 on line 0
  lcd.print("Open the damn");
  lcd.setCursor(0,1); // Start at character 0 on line 1
  lcd.print("blinds!");  

  { 
  // scroll 13 positions (string length) to the left
  // to move it offscreen left:
  for (int positionCounter = 0; positionCounter < 13; positionCounter++) {
    // scroll one position left:
    lcd.scrollDisplayLeft();

  }

  // scroll 29 positions (string length + display length) to the right
  // to move it offscreen right:
  for (int positionCounter = 0; positionCounter < 29; positionCounter++) {
    // scroll one position right:
    lcd.scrollDisplayRight();
  
  }

  // scroll 16 positions (display length + string length) to the left
  // to move it back to center:
  for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
    // scroll one position left:
    lcd.scrollDisplayLeft();
  }  
}

lcd.clear();
 for(int i = 0; i< 3; i++)
  {
    lcd.backlight();
    lcd.noBacklight();
  }
  lcd.backlight();
  lcd.setCursor(0,0); //Start at character 0 on line 0
  lcd.print("Or else, innocent");
  lcd.setCursor(0,1);
  lcd.print("plants will die.");  
  {
  
  { 
  for (int positionCounter = 0; positionCounter < 13; positionCounter++) {
    lcd.scrollDisplayLeft();
  }

  for (int positionCounter = 0; positionCounter < 29; positionCounter++) {
    lcd.scrollDisplayRight();
  }

 { 
  for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
    lcd.scrollDisplayLeft();
    }

}
 }
  }  
  } 
};

Display display1();
 
void setup() 
{  
  twist1.Attach(9); 
} 
 
 
void loop() 
{ 
  twist1.Update();
  display1. Update();
   
};

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 9, 2018, 12:01am UTC](https://forum.arduino.cc/t/need-help-debugging-lcd-display-servo-state-machine-code/512904/2 "2018-03-09T00:01:21Z")

</div>

```cpp
void Update()

ldrState = digitalRead(ldrPin); //read the digital state of ldrPin with digitalRead() function and store the value in ldrState variable

{

```

In any of your other functions, what goes between the ) and the {? Hint: NOTHING. Why did you try to change that here?

You really should define your classes in a header file and implement them in a source file. Then, you'd understand why the class knows nothing about the lcd instance.

---

<div class="post-metadata">

**Author:** ![cmp3mt](https://avatars.discourse-cdn.com/v4/letter/c/f6c823/32.png) [@cmp3mt](https://forum.arduino.cc/u/cmp3mt)\
**Post date:** [March 9, 2018, 12:13am UTC](https://forum.arduino.cc/t/need-help-debugging-lcd-display-servo-state-machine-code/512904/3 "2018-03-09T00:13:26Z")

</div>

Thanks for the help, I'll implement these changes and give an update later!

---

<div class="post-metadata">

**Author:** ![cmp3mt](https://avatars.discourse-cdn.com/v4/letter/c/f6c823/32.png) [@cmp3mt](https://forum.arduino.cc/u/cmp3mt)\
**Post date:** [March 9, 2018, 12:51am UTC](https://forum.arduino.cc/t/need-help-debugging-lcd-display-servo-state-machine-code/512904/4 "2018-03-09T00:51:54Z")

</div>

Okay, so I'm not entirely sure if I did what you said to but I'm getting this error message now:

/Users/caitlinpeterson/Documents/Arduino/Blinds\_Controller/Blinds\_Controller.ino:13:19: fatal error: Twist.h: No such file or directory  
#include "Twist.h"  
^  
compilation terminated.  
exit status 1  
Error compiling for board Arduino/Genuino Uno.

Here's the modified code:

```cpp
#ifndef Twist_h
#define Twist_h

#ifndef Display_h
#define Display_h

#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 16, 2);

#include "Arduino.h"
#include "Twist.h"
#include "Display.h"

class Twist
{
  const int servoPin = 9; // servo pin 
  Servo servo;              // the servo
  int pos = 0;  // variable to store the servo position
  int directionState = 0;
  int increment;        // increment to move for each interval
  int  updateInterval;      // interval between updates
  unsigned long lastUpdate; // last update of position

  const int buttonPin = 8; // pushbutton pin
int buttonState = 0;
 
public: 

  Twist(int interval)
  {
    updateInterval = interval;
    increment = 1;
  }

  
  void Attach(int pin)
  {
    servo.attach(9);
  }
  
  void Detach()
  {
    servo.detach();
  }
  
  void Update()
  {
    if((millis() - lastUpdate) > updateInterval)  // time to update
    {
      lastUpdate = millis();
      pos += increment;
  
  buttonState = digitalRead(buttonPin);
   
  if (directionState == 0) {
    if (buttonState == HIGH) {
      directionState = 1;
      for (pos = 20; pos < 180; pos = pos + 1) {
        servo.write(pos);
      }
    }
  } else if (directionState == 1) {
    if (buttonState == HIGH) {
      directionState = 0;
      for (pos = 180; pos > 1; pos = pos - 1) {
        servo.write(pos);
      }
    }
  }
 
    }
  }
};
 
Twist twist1(15);

#endif

class Display
{
  
lcd.begin();

const int ldrPin = 7;  // light dependent resistor pin
int ldrState; // local variable to hold ldr states

public:

void Message1()

{

ldrState = digitalRead(ldrPin); //read the digital state of ldrPin with digitalRead() function and store the value in ldrState variable 
if (ldrState == HIGH)
{ 
  lcd.clear();
  lcd.setCursor(0,0); //Start at character 0 on line 0
  lcd.print("Open the damn");
  lcd.setCursor(0,1); // Start at character 0 on line 1
  lcd.print("blinds!");  
  { 
  // scroll 13 positions (string length) to the left
  // to move it offscreen left:
  for (int positionCounter = 0; positionCounter < 13; positionCounter++) {
    // scroll one position left:
    lcd.scrollDisplayLeft();

  }

  // scroll 29 positions (string length + display length) to the right
  // to move it offscreen right:
  for (int positionCounter = 0; positionCounter < 29; positionCounter++) {
    // scroll one position right:
    lcd.scrollDisplayRight();
  
  }

  // scroll 16 positions (display length + string length) to the left
  // to move it back to center:
  for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
    // scroll one position left:
    lcd.scrollDisplayLeft();
  }  
}

void Message2()
{
lcd.clear();
 for(int i = 0; i< 3; i++)
  {
    lcd.backlight();
    lcd.noBacklight();
  }
  lcd.backlight();
  lcd.setCursor(0,0); //Start at character 0 on line 0
  lcd.print("Or else, innocent");
  lcd.setCursor(0,1);
  lcd.print("plants will die.");  
  {
  
  { 
  for (int positionCounter = 0; positionCounter < 13; positionCounter++) {
    lcd.scrollDisplayLeft();
  }

  for (int positionCounter = 0; positionCounter < 29; positionCounter++) {
    lcd.scrollDisplayRight();
  }

 { 
  for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
    lcd.scrollDisplayLeft();
    }

}
 }
  }  
  } 
}
};

Display diplay1();

#endif
 
void setup() 
{  
  twist1.Attach(9); 
} 
 
 
void loop() 
{ 
  twist1.Update();
  display1.Message1();
  display1.Message2();
};

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 9, 2018, 1:35am UTC](https://forum.arduino.cc/t/need-help-debugging-lcd-display-servo-state-machine-code/512904/5 "2018-03-09T01:35:11Z")

</div>

```cpp
#ifndef Twist_h
#define Twist_h

#ifndef Display_h
#define Display_h

```

Why do you have two include guards in one file? That IS one file, isn't it?

It should be 4 files! 2 DIFFERENT header (.h) and 2 DIFFERENT source (cpp) files.

---

<div class="post-metadata">

**Author:** ![cmp3mt](https://avatars.discourse-cdn.com/v4/letter/c/f6c823/32.png) [@cmp3mt](https://forum.arduino.cc/u/cmp3mt)\
**Post date:** [March 9, 2018, 4:31am UTC](https://forum.arduino.cc/t/need-help-debugging-lcd-display-servo-state-machine-code/512904/6 "2018-03-09T04:31:48Z")

</div>

I'm not necessarily sure what you mean by including two guards in one file. In addition, I do have four different files. I followed this: [https://www.arduino.cc/en/Hacking/LibraryTutorial](https://www.arduino.cc/en/Hacking/LibraryTutorial) -- in attempting to fix my code.

Here's my error message:

/Users/caitlinpeterson/Documents/Arduino/Blinds\_Controller/Blinds\_Controller.ino: In function 'void loop()':  
Blinds\_Controller:188: error: 'display1' was not declared in this scope  
display1.Message1();  
^  
exit status 1  
'display1' was not declared in this scope

Here's my current code:

```cpp
#ifndef Twist_h
#define Twist_h

#include "Arduino.h"
#include "Twist.h"
#include <Servo.h>

class Twist
{
  const int servoPin = 9; // servo pin 
  Servo servo;              // the servo
  int pos = 0;  // variable to store the servo position
  int directionState = 0;
  int increment;        // increment to move for each interval
  int  updateInterval;      // interval between updates
  unsigned long lastUpdate; // last update of position

  const int buttonPin = 8; // pushbutton pin
int buttonState = 0;
 
public: 
 Twist(int interval);
 void Attach(int pin);
 void Detach();
 void Update();
};

#include "Arduino.h"
#include "Twist.h"

 Twist::Twist(int interval)
  {
    updateInterval = interval;
    increment = 1;
  }

  
  void Twist::Attach(int pin)
  {
    servo.attach(9);
  }
  
  void Twist::Detach()
  {
    servo.detach();
  }
  
  void Twist::Update()
  {
    if((millis() - lastUpdate) > updateInterval)  // time to update
    {
      lastUpdate = millis();
      pos += increment;
  
   buttonState = digitalRead(buttonPin);
   
  if (directionState == 0) {
    if (buttonState == HIGH) {
      directionState = 1;
      for (pos = 20; pos < 180; pos = pos + 1) {
        servo.write(pos);
      }
    }
  } else if (directionState == 1) {
    if (buttonState == HIGH) {
      directionState = 0;
      for (pos = 180; pos > 1; pos = pos - 1) {
        servo.write(pos);
      }
    }
  }
 
    }
  };

#endif
 
Twist twist1(15);

#include "Display.h"
#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

#ifndef Display_h
#define Display_h

class Display
{
  
lcd.begin();

const int ldrPin = 7;  // light dependent resistor pin
int ldrState; // local variable to hold ldr states

public:
void Message1();
};

void Display::Message1()

{
ldrState = digitalRead(ldrPin); //read the digital state of ldrPin with digitalRead() function and store the value in ldrState variable 
if (ldrState == HIGH)
{ 
  lcd.clear();
  lcd.setCursor(0,0); //Start at character 0 on line 0
  lcd.print("Open the damn");
  lcd.setCursor(0,1); // Start at character 0 on line 1
  lcd.print("blinds!");  
   { 
  // scroll 13 positions (string length) to the left
  // to move it offscreen left:
  for (int positionCounter = 0; positionCounter < 13; positionCounter++) {
    // scroll one position left:
    lcd.scrollDisplayLeft();

  }

  // scroll 29 positions (string length + display length) to the right
  // to move it offscreen right:
  for (int positionCounter = 0; positionCounter < 29; positionCounter++) {
    // scroll one position right:
    lcd.scrollDisplayRight();
  
  }

  // scroll 16 positions (display length + string length) to the left
  // to move it back to center:
  for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
    // scroll one position left:
    lcd.scrollDisplayLeft();
  }  
{
lcd.clear();
 for(int i = 0; i< 3; i++)
  {
    lcd.backlight();
    lcd.noBacklight();
  }
  lcd.backlight();
  lcd.setCursor(0,0); //Start at character 0 on line 0
  lcd.print("Or else, innocent");
  lcd.setCursor(0,1);
  lcd.print("plants will die.");  
  {
  
  { 
  for (int positionCounter = 0; positionCounter < 13; positionCounter++) {
    lcd.scrollDisplayLeft();
  }

  for (int positionCounter = 0; positionCounter < 29; positionCounter++) {
    lcd.scrollDisplayRight();
  }

 { 
  for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
    lcd.scrollDisplayLeft();
     }

}
 }
  }  
   } 
}
};

Display display1();

#endif
 
void setup() 
{  
  twist1.Attach(9); 
} 
 
 
void loop() 
{ 
  twist1.Update();
  display1.Message1();
};

```

---

<div class="post-metadata">

**Author:** ![cmp3mt](https://avatars.discourse-cdn.com/v4/letter/c/f6c823/32.png) [@cmp3mt](https://forum.arduino.cc/u/cmp3mt)\
**Post date:** [March 9, 2018, 4:37am UTC](https://forum.arduino.cc/t/need-help-debugging-lcd-display-servo-state-machine-code/512904/7 "2018-03-09T04:37:34Z")

</div>

Here's Twist.h:

```cpp
 #ifndef Twist_h
 #define Twist_h
 #include "Arduino.h"
 #include "Twist.h"
 #include <Servo.h>
 
 class Twist
 {
   const int servoPin = 9; // servo pin 
   Servo servo;              // the servo
   int pos = 0;  // variable to store the servo position
   int directionState = 0;
   int increment;        // increment to move for each interval
   int  updateInterval;      // interval between updates
   unsigned long lastUpdate; // last update of position
 
   const int buttonPin = 8; // pushbutton pin
 int buttonState = 0;
  
 public: 
  Twist(int interval);
  void Attach(int pin);
  void Detach();
  void Update();
 };

 #endif

```

Here's Twist.cpp:

```cpp
 #include "Arduino.h"
 #include "Twist.h"
 #include <Servo.h>
 
  Twist::Twist(int interval)
   {
     updateInterval = interval;
     increment = 1;
   }
 
  void Twist::Attach(int pin)
   {
     servo.attach(9);
   }
   void Twist::Detach()
   {
     servo.detach();
   }

   void Twist::Update()

   {
     if((millis() - lastUpdate) > updateInterval)  // time to update
     {
       lastUpdate = millis();
       pos += increment;

    buttonState = digitalRead(buttonPin);
   if (directionState == 0) {
     if (buttonState == HIGH) {
       directionState = 1;
       for (pos = 20; pos < 180; pos = pos + 1) {
         servo.write(pos);
       }
     }
   } else if (directionState == 1) {
     if (buttonState == HIGH) {
       directionState = 0;
       for (pos = 180; pos > 1; pos = pos - 1) {
         servo.write(pos);
       }
     }
   }
     }

```

Here's Display.h:

```cpp
#ifndef Display_h
 #define Display_h
 #include "Display.h"
 #include <Wire.h>
 #include <LiquidCrystal_I2C.h>
  LiquidCrystal_I2C lcd(0x3F, 16, 2);
 
 class Display
 {
 
 const int ldrPin = 7;  // light dependent resistor pin
 int ldrState; // local variable to hold ldr states
 
public:
 void Message1();
 };
  #endif

```

Here's Display.cpp:

```cpp
void Display::Message1()
{
 lcd.begin();
 ldrState = digitalRead(ldrPin); //read the digital state of ldrPin with digitalRead() function and store the value in ldrState variable 
 if (ldrState == HIGH)
 { 
   lcd.clear();
   lcd.setCursor(0,0); //Start at character 0 on line 0
   lcd.print("Open the damn");
   lcd.setCursor(0,1); // Start at character 0 on line 1
   lcd.print("blinds!");  
    { 
   // scroll 13 positions (string length) to the left
   // to move it offscreen left:
   for (int positionCounter = 0; positionCounter < 13; positionCounter++) {
     // scroll one position left:
     lcd.scrollDisplayLeft();
   }
   // scroll 29 positions (string length + display length) to the right
   // to move it offscreen right:
  for (int positionCounter = 0; positionCounter < 29; positionCounter++) {
    // scroll one position right:
    lcd.scrollDisplayRight();
  
  }

  // scroll 16 positions (display length + string length) to the left
  // to move it back to center:
  for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
    // scroll one position left:
    lcd.scrollDisplayLeft();
  }  
{
lcd.clear();
 for(int i = 0; i< 3; i++)
  {
    lcd.backlight();
    lcd.noBacklight();
  }
  lcd.backlight();
  lcd.setCursor(0,0); //Start at character 0 on line 0
  lcd.print("Or else, innocent");
  lcd.setCursor(0,1);
  lcd.print("plants will die.");  
  {
  
  { 
  for (int positionCounter = 0; positionCounter < 13; positionCounter++) {
    lcd.scrollDisplayLeft();
  }

  for (int positionCounter = 0; positionCounter < 29; positionCounter++) {
    lcd.scrollDisplayRight();
  }

 { 
  for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
    lcd.scrollDisplayLeft();
    for (int positionCounter = 0; positionCounter < 29; positionCounter++) {
     // scroll one position right:
     lcd.scrollDisplayRight();
   }
   // scroll 16 positions (display length + string length) to the left
   // to move it back to center:
   for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
     // scroll one position left:
     lcd.scrollDisplayLeft();
   }  
 {
 lcd.clear();
  for(int i = 0; i< 3; i++)
   {
     lcd.backlight();
     lcd.noBacklight();
   }
   lcd.backlight();
   lcd.setCursor(0,0); //Start at character 0 on line 0
   lcd.print("Or else, innocent");
   lcd.setCursor(0,1);
   lcd.print("plants will die.");  
   {
   
   { 
   for (int positionCounter = 0; positionCounter < 13; positionCounter++) {
     lcd.scrollDisplayLeft();
   }
   for (int positionCounter = 0; positionCounter < 29; positionCounter++) {
     lcd.scrollDisplayRight();
   }
  { 
   for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
     lcd.scrollDisplayLeft();
      }
 }
  }
   }  
    } 
 }

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 9, 2018, 4:47am UTC](https://forum.arduino.cc/t/need-help-debugging-lcd-display-servo-state-machine-code/512904/8 "2018-03-09T04:47:17Z")

</div>

Why does Twist.h try to include Twist.h?

---

<div class="post-metadata">

**Author:** ![cmp3mt](https://avatars.discourse-cdn.com/v4/letter/c/f6c823/32.png) [@cmp3mt](https://forum.arduino.cc/u/cmp3mt)\
**Post date:** [March 9, 2018, 5:01am UTC](https://forum.arduino.cc/t/need-help-debugging-lcd-display-servo-state-machine-code/512904/9 "2018-03-09T05:01:11Z")

</div>

Ahh, I see...

---

<div class="post-metadata">

**Author:** ![cmp3mt](https://avatars.discourse-cdn.com/v4/letter/c/f6c823/32.png) [@cmp3mt](https://forum.arduino.cc/u/cmp3mt)\
**Post date:** [March 9, 2018, 5:08am UTC](https://forum.arduino.cc/t/need-help-debugging-lcd-display-servo-state-machine-code/512904/10 "2018-03-09T05:08:44Z")

</div>

Okay, I removed the unnecessary includes but am still receiving the same error message, along with the "lcd does not name a type" error

---

<div class="post-metadata">

**Author:** ![cmp3mt](https://avatars.discourse-cdn.com/v4/letter/c/f6c823/32.png) [@cmp3mt](https://forum.arduino.cc/u/cmp3mt)\
**Post date:** [March 9, 2018, 5:41am UTC](https://forum.arduino.cc/t/need-help-debugging-lcd-display-servo-state-machine-code/512904/11 "2018-03-09T05:41:54Z")

</div>

New errors:  
In file included from /Users/caitlinpeterson/Documents/Arduino/Blinds\_Controller/Blinds\_Controller.ino:1:0:  
Display.h:12: error: 'lcd' does not name a type  
lcd.begin();  
^  
/Users/caitlinpeterson/Documents/Arduino/Blinds\_Controller/Blinds\_Controller.ino: In function 'void loop()':  
Blinds\_Controller:20: error: request for member 'Message1' in 'display1', which is of non-class type 'Display()'  
display1.Message1();  
^  
exit status 1  
'lcd' does not name a type

Here's my new code:

```cpp
#include <Display.h>
#include <Twist.h>

 
Twist twist1(15);

Display display1();

 
void setup() 
{  
  twist1.Attach(9); 
} 
 
 
void loop() 
{ 
  twist1.Update();
  display1.Message1();
};

```

and modified .h and .cpp files:

```cpp
  #ifndef Twist_h
 #define Twist_h
 #include "Arduino.h"
 #include <Servo.h>
 
 class Twist
 {
  const int servoPin = 9; // servo pin 
  Servo servo;              // the servo
  int pos = 0;  // variable to store the servo position
  int directionState = 0;
  int increment;        // increment to move for each interval
  int  updateInterval;      // interval between updates
  unsigned long lastUpdate; // last update of position
 
  const int buttonPin = 8; // pushbutton pin
 int buttonState = 0;
  
 public: 
  Twist(int interval);
  void Attach(int pin);
  void Detach();
  void Update();
 };

 #endif

```

```cpp
 #include "Arduino.h"
 #include "Twist.h"
 #include <Servo.h>
 
  Twist::Twist(int interval)
  {
    updateInterval = interval;
    increment = 1;
  }
 
  void Twist::Attach(int pin)
  {
    servo.attach(9);
  }
  void Twist::Detach()
  {
    servo.detach();
  }

  void Twist::Update()

  {
    if((millis() - lastUpdate) > updateInterval)  // time to update
    {
      lastUpdate = millis();
      pos += increment;

    buttonState = digitalRead(buttonPin);
  if (directionState == 0) {
    if (buttonState == HIGH) {
      directionState = 1;
      for (pos = 20; pos < 180; pos = pos + 1) {
        servo.write(pos);
      }
    }
  } 
  else if (directionState == 1) {
    if (buttonState == HIGH) {
      directionState = 0;
      for (pos = 180; pos > 1; pos = pos - 1) {
        servo.write(pos);
      }
    }
  }
    }
  }

```

```cpp
 #ifndef Display_h
 #define Display_h

 #include <Wire.h>
 #include <LiquidCrystal_I2C.h>
  LiquidCrystal_I2C lcd(0x3F, 16, 2);

 
 class Display
 {
  lcd.begin();
 const int ldrPin = 7;  // light dependent resistor pin
 int ldrState; // local variable to hold ldr states
 
public:
 void Message1();
 };
  #endif

```

```cpp
#include "Display.h"

void Display::Message1()
{
 lcd.begin();
 ldrState = digitalRead(ldrPin); //read the digital state of ldrPin with digitalRead() function and store the value in ldrState variable 
 if (ldrState == HIGH)
 { 
  lcd.clear();
  lcd.setCursor(0,0); //Start at character 0 on line 0
  lcd.print("Open the damn");
  lcd.setCursor(0,1); // Start at character 0 on line 1
  lcd.print("blinds!");  
    { 
  // scroll 13 positions (string length) to the left
  // to move it offscreen left:
  for (int positionCounter = 0; positionCounter < 13; positionCounter++) {
    // scroll one position left:
    lcd.scrollDisplayLeft();
  }
  // scroll 29 positions (string length + display length) to the right
  // to move it offscreen right:
  for (int positionCounter = 0; positionCounter < 29; positionCounter++) {
    // scroll one position right:
    lcd.scrollDisplayRight();
  
  }

  // scroll 16 positions (display length + string length) to the left
  // to move it back to center:
  for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
    // scroll one position left:
    lcd.scrollDisplayLeft();
  }  
{
lcd.clear();
 for(int i = 0; i< 3; i++)
  {
    lcd.backlight();
    lcd.noBacklight();
  }
  lcd.backlight();
  lcd.setCursor(0,0); //Start at character 0 on line 0
  lcd.print("Or else, innocent");
  lcd.setCursor(0,1);
  lcd.print("plants will die.");  
  {
  
  { 
  for (int positionCounter = 0; positionCounter < 13; positionCounter++) {
    lcd.scrollDisplayLeft();
  }

  for (int positionCounter = 0; positionCounter < 29; positionCounter++) {
    lcd.scrollDisplayRight();
  }

 { 
  for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
    lcd.scrollDisplayLeft();
    for (int positionCounter = 0; positionCounter < 29; positionCounter++) {
    // scroll one position right:
    lcd.scrollDisplayRight();
  }
  // scroll 16 positions (display length + string length) to the left
  // to move it back to center:
  for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
    // scroll one position left:
    lcd.scrollDisplayLeft();
  }  
 {
 lcd.clear();
  for(int i = 0; i< 3; i++)
  {
    lcd.backlight();
    lcd.noBacklight();
  }
  lcd.backlight();
  lcd.setCursor(0,0); //Start at character 0 on line 0
  lcd.print("Or else, innocent");
  lcd.setCursor(0,1);
  lcd.print("plants will die.");  
  {
   
  { 
  for (int positionCounter = 0; positionCounter < 13; positionCounter++) {
    lcd.scrollDisplayLeft();
  }
  for (int positionCounter = 0; positionCounter < 29; positionCounter++) {
    lcd.scrollDisplayRight();
  }
  { 
  for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
    lcd.scrollDisplayLeft();
      }
 }
  }
  }  
    } 
 }

```

---

<div class="post-metadata">

**Author:** ![cmp3mt](https://avatars.discourse-cdn.com/v4/letter/c/f6c823/32.png) [@cmp3mt](https://forum.arduino.cc/u/cmp3mt)\
**Post date:** [March 9, 2018, 6:36pm UTC](https://forum.arduino.cc/t/need-help-debugging-lcd-display-servo-state-machine-code/512904/12 "2018-03-09T18:36:42Z")

</div>

I'm having a couple issues with my code. The code should be able to display a message on an lcd when a light dependent resistor senses light and operate a motor via a button push.

**Here are my error messages:**

In file included from /Users/caitlinpeterson/Documents/Arduino/Blinds\_Controller/Blinds\_Controller.ino:1:0:  
Display.h:12: error: 'lcd' does not name a type  
lcd.begin();  
^  
/Users/caitlinpeterson/Documents/Arduino/Blinds\_Controller/Blinds\_Controller.ino: In function 'void loop()':  
Blinds\_Controller:20: error: request for member 'Message1' in 'display1', which is of non-class type 'Display()'  
display1.Message1();  
^  
exit status 1  
'lcd' does not name a type

**Here's my code:**

```cpp
#include <Display.h>
#include <Twist.h>

 
Twist twist1(15);

Display display1();

 
void setup() 
{  
  twist1.Attach(9); 
} 
 
 
void loop() 
{ 
  twist1.Update();
  display1.Message1();
};

```

**Here's Twist.h:**

```cpp
#ifndef Twist_h
 #define Twist_h
 #include "Arduino.h"
 #include <Servo.h>
 
 class Twist
 {
  const int servoPin = 9; // servo pin 
  Servo servo;              // the servo
  int pos = 0;  // variable to store the servo position
  int directionState = 0;
  int increment;        // increment to move for each interval
  int  updateInterval;      // interval between updates
  unsigned long lastUpdate; // last update of position
 
  const int buttonPin = 8; // pushbutton pin
 int buttonState = 0;
  
 public: 
  Twist(int interval);
  void Attach(int pin);
  void Detach();
  void Update();
 };

 #endif

```

**Here's Twist.cpp:**

```cpp
 #include "Arduino.h"
 #include <Twist.h>
 #include <Servo.h>
 
  Twist::Twist(int interval)
  {
    updateInterval = interval;
    increment = 1;
  }
 
  void Twist::Attach(int pin)
  {
    servo.attach(9);
  }
  void Twist::Detach()
  {
    servo.detach();
  }

  void Twist::Update()

  {
    if((millis() - lastUpdate) > updateInterval)  // time to update
    {
      lastUpdate = millis();
      pos += increment;

    buttonState = digitalRead(buttonPin);
  if (directionState == 0) {
    if (buttonState == HIGH) {
      directionState = 1;
      for (pos = 20; pos < 180; pos = pos + 1) {
        servo.write(pos);
      }
    }
  } 
  else if (directionState == 1) {
    if (buttonState == HIGH) {
      directionState = 0;
      for (pos = 180; pos > 1; pos = pos - 1) {
        servo.write(pos);
      }
    }
  }
    }
  }

```

**Here's Display.h:**

```cpp
#include "Arduino.h"
 #include <Wire.h>
 #include <LiquidCrystal_I2C.h>

  LiquidCrystal_I2C lcd(0x3F, 16, 2);

 
 class Display
 {
 lcd.begin(16, 2);
  
 const int ldrPin = 7;  // light dependent resistor pin
 int ldrState; // local variable to hold ldr states
 
public:
 void Message1();
 };
  #endif

```

**Here's Display.cpp:**

```cpp
#include "Display.h"
#include <LiquidCrystal_I2C.h> 
#include "Arduino.h" 

void Display::Message1()
{
 ldrState = digitalRead(ldrPin); //read the digital state of ldrPin with digitalRead() function and store the value in ldrState variable 
 if (ldrState == HIGH)
 { 
  lcd.clear();
  lcd.setCursor(0,0); //Start at character 0 on line 0
  lcd.print("Open the damn");
  lcd.setCursor(0,1); // Start at character 0 on line 1
  lcd.print("blinds!");  
    { 
  // scroll 13 positions (string length) to the left
  // to move it offscreen left:
  for (int positionCounter = 0; positionCounter < 13; positionCounter++) {
    // scroll one position left:
    lcd.scrollDisplayLeft();
  }
  // scroll 29 positions (string length + display length) to the right
  // to move it offscreen right:
  for (int positionCounter = 0; positionCounter < 29; positionCounter++) {
    // scroll one position right:
    lcd.scrollDisplayRight();
  
  }

  // scroll 16 positions (display length + string length) to the left
  // to move it back to center:
  for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
    // scroll one position left:
    lcd.scrollDisplayLeft();
  }  
{
lcd.clear();
 for(int i = 0; i< 3; i++)
  {
    lcd.backlight();
    lcd.noBacklight();
  }
  lcd.backlight();
  lcd.setCursor(0,0); 
  lcd.print("Or else, innocent");
  lcd.setCursor(0,1);
  lcd.print("plants will die.");  
  {
  
  { 
  for (int positionCounter = 0; positionCounter < 13; positionCounter++) {
    lcd.scrollDisplayLeft();
  }

  for (int positionCounter = 0; positionCounter < 29; positionCounter++) {
    lcd.scrollDisplayRight();
  }

 { 
  for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
    lcd.scrollDisplayLeft();
  }  
 
 }
  }
  }  
    } 
    }
 } 
}

```

---

<div class="post-metadata">

**Author:** ![cmp3mt](https://avatars.discourse-cdn.com/v4/letter/c/f6c823/32.png) [@cmp3mt](https://forum.arduino.cc/u/cmp3mt)\
**Post date:** [March 9, 2018, 6:50pm UTC](https://forum.arduino.cc/t/need-help-debugging-lcd-display-servo-state-machine-code/512904/13 "2018-03-09T18:50:17Z")

</div>

I managed to fix the non-class type error by changing this:

```cpp
Display display1();

```

to this:

```cpp
Display display1;

```

However, I'm still unsure off how to solve the 'lcd does not name a type error'

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 12, 2018, 9:17am UTC](https://forum.arduino.cc/t/need-help-debugging-lcd-display-servo-state-machine-code/512904/14 "2018-03-12T09:17:33Z")

</div>

```cpp
      for (pos = 20; pos < 180; pos = pos + 1) {
        servo.write(pos);
      }

```

How long will it take this loop to tell the servo to go to position 179? What will the servo position be when the code tells the servo to go to position 179?

```cpp
  LiquidCrystal_I2C lcd(0x3F, 16, 2);

 
 class Display
 {

```

Why is the lcd instance not a member of the class?

```cpp
 ldrState = digitalRead(ldrPin); //read the digital state of ldrPin with digitalRead() function and store the value in ldrState variable

```

Does that comment provide ANY value? Anyone can see that digitalRead() is used, and that the result is stored in ldrState.

What needs explaining is why an analog device is being read as though it was a digital device.

```cpp
  lcd.print("blinds!"); 
    {

```

What is that curly brace for?

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 12, 2018, 9:48am UTC](https://forum.arduino.cc/t/need-help-debugging-lcd-display-servo-state-machine-code/512904/15 "2018-03-12T09:48:01Z")

</div>

> However, I'm still unsure off how to solve the 'lcd does not name a type error'

Creating MORE threads is NOT the solution. NO MORE NEW THREADS!

---

<div class="post-metadata">

**Author:** ![robtillaart](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/robtillaart/32/1098811_2.png) [@robtillaart](https://forum.arduino.cc/u/robtillaart)\
**Post date:** [March 12, 2018, 11:10am UTC](https://forum.arduino.cc/t/need-help-debugging-lcd-display-servo-state-machine-code/512904/16 "2018-03-12T11:10:55Z")

</div>

Moderator merged topics

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 11:03pm UTC](https://forum.arduino.cc/t/need-help-debugging-lcd-display-servo-state-machine-code/512904/17 "2021-05-05T23:03:31Z")

</div>


