Combining Sketches

Hi Everyone.

I have to separate sketches that i'm trying to combine and am having trouble integrating one to another.

The two you tube videos below are of the sketches working separately. However I need help in combining both to make essentially a button operated servo tester with an output readout.

Hi,

Some suggestions here:

http://arduino-info.wikispaces.com/CombiningArduinoSketches

Than you terry. I guess the issue is that i'm new to this and I don't completely understand the coding and logic 100% the guide is helpful, however I will need to spend time learning the structure and what is required. unless anyone here I can throw both sketches at and they are able to help me through it and let me know the reasoning and structure behind the combination.

Hi,
You would need to post both sketches here, with code tags. Read:

http://forum.arduino.cc/index.php?topic=149014.0

Someone may be able to help. Since this is the 4th of July in USA, I am doing plumbing today...

Thank you Terry

#include<Servo.h>
int pos = 0;
Servo servo;
void setup() {
pinMode(2, INPUT);
pinMode(3, INPUT);
servo.attach(9);
}
void loop() {
while (digitalRead(2) == HIGH && pos < 180) {
  pos++;
  servo.write(pos);
  delay(15);
}
while (digitalRead(3) == HIGH && pos > 0) {
  pos--;
  servo.write(pos);
  delay(15);
}
}

It may be easier to do a servo tester with a pot instead of buttons.

The servo knob example that comes with the servo library uses a potentiomter to adjust the position of a servo.

This tutorial shows how to use a LCD to display the pot data.

Combine those sketches to make a servo tester.

This Simple Merge Demo may help.

Before trying to merge the programs go through each of them carefully to make sure they are not trying to use the same resource - for examples an I/O pin. If you find conflicts change something in one of the separate programs and make sure it still works with the change.

...R

I am aware of some of the fundamentals like input and output pins and I am able to change these easily. I am having trouble in how to structure and where to put the lines of code from the two sketches.

unfortunately A potentiometer can not be used because of the application of the project. The idea is that the servo can be controlled either direction with two buttons. and the LCD will give an indication of where the servo is in it's stroke. It's being used on a gokart carburettor to allow the driver to live tune as he goes.

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3F,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display

int counter = 0;

// this constant won't change:
const int  Up_buttonPin   = 2;    // the pin that the pushbutton is attached to
const int  Down_buttonPin = 3;

// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
int up_buttonState = 0;         // current state of the up button
int up_lastButtonState = 0;     // previous state of the up button

int down_buttonState = 0;         // current state of the up button
int down_lastButtonState = 0;     // previous state of the up button
bool bPress = false;

byte LT[8] = 
{

  B00111,
  B01111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111
};
byte UB[8] =
{
  B11111,
  B11111,
  B11111,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000
};
byte RT[8] =
{

  B11100,
  B11110,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111
};
byte LL[8] =
{


  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B01111,
  B00111
};
byte LB[8] =
{
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B11111,
  B11111,
  B11111
};
byte LR[8] =
{


  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11110,
  B11100
};
byte MB[8] =
{
  B11111,
  B11111,
  B11111,
  B00000,
  B00000,
  B00000,
  B11111,
  B11111
};
byte block[8] =
{
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11111
};

void setup()
{
  pinMode( Up_buttonPin , INPUT_PULLUP);
  pinMode( Down_buttonPin , INPUT_PULLUP);
  
  lcd.init();                      // initialize the lcd 

  lcd.createChar(0,LT);
  lcd.createChar(1,UB);
  lcd.createChar(2,RT);
  lcd.createChar(3,LL);
  lcd.createChar(4,LB);
  lcd.createChar(5,LR);
  lcd.createChar(6,MB);
  lcd.createChar(7,block);
  
  // Print a message to the LCD.
  lcd.backlight();
   
  lcd.clear();

  displayNumber();
   
}

void printNumber(int val){
  
     int col=5;     
     
     if( val >= 10){
       printDigits(val/10,col);     
       printDigits(val%10,col+4);
     }
     else{
       printDigits(val,col);
     }
}

void loop()
{
   checkUp();
   checkDown();

   if( bPress){
       bPress = false;
       displayNumber();
   }
}
void displayNumber(){
    
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Vol:"); 
    printNumber( buttonPushCounter);
    
}
void custom0(int x){ 

  lcd.setCursor(x,0); 
  lcd.write(0);  
  lcd.write(1);  
  lcd.write(2);
  lcd.setCursor(x, 1); 
  lcd.write(3);  
  lcd.write(4);  
  lcd.write(5);
}

void custom1(int x){
  lcd.setCursor(x,0);
  lcd.write(1);
  lcd.write(2);
  lcd.print(" ");
  lcd.setCursor(x,1);
  lcd.write(4);
  lcd.write(7);
  lcd.write(4);
}

void custom2(int x){
  lcd.setCursor(x,0);
  lcd.write(6);
  lcd.write(6);
  lcd.write(2);
  lcd.setCursor(x, 1);
  lcd.write(3);
  lcd.write(4);
  lcd.write(4);
}

void custom3(int x){
  lcd.setCursor(x,0);
  lcd.write(6);
  lcd.write(6);
  lcd.write(2);
  lcd.setCursor(x, 1);
  lcd.write(4);
  lcd.write(4);
  lcd.write(5); 
}

void custom4(int x){
  lcd.setCursor(x,0);
  lcd.write(3);
  lcd.write(4);
  lcd.write(7);
  lcd.setCursor(x, 1);
  lcd.print(" ");
  lcd.print(" ");
  lcd.write(7);
}

void custom5(int x){
  lcd.setCursor(x,0);
  lcd.write(3);
  lcd.write(6);
  lcd.write(6);
  lcd.setCursor(x, 1);
  lcd.write(4);
  lcd.write(4);
  lcd.write(5);
}

void custom6(int x){
  lcd.setCursor(x,0);
  lcd.write(0);
  lcd.write(6);
  lcd.write(6);
  lcd.setCursor(x, 1);
  lcd.write(3);
  lcd.write(4);
  lcd.write(5);
}

void custom7(int x){
  lcd.setCursor(x,0);
  lcd.write(1);
  lcd.write(1);
  lcd.write(2);
  lcd.setCursor(x, 1);
  lcd.print(" ");
  lcd.print(" ");
  lcd.write(7);
}

void custom8(int x){
  lcd.setCursor(x,0);
  lcd.write(0);
  lcd.write(6);
  lcd.write(2);
  lcd.setCursor(x, 1);
  lcd.write(3);
  lcd.write(4);
  lcd.write(5);
}

void custom9(int x){
  
  lcd.setCursor(x,0);
  lcd.write(0);
  lcd.write(6);
  lcd.write(2);
  lcd.setCursor(x, 1);
  lcd.print(" ");
  lcd.print(" ");
  lcd.write(7);

}
void printDigits(int digits, int x){
  // utility function for digital clock display: prints preceding colon and leading 0

  switch (digits) {
  case 0:  
    custom0(x);
    break;
  case 1:  
    custom1(x);
    break;
  case 2:  
    custom2(x);
    break;
  case 3:  
    custom3(x);
    break;
  case 4:  
    custom4(x);
    break;
  case 5:  
    custom5(x);
    break;
  case 6:  
    custom6(x);
    break;
  case 7:  
    custom7(x);
    break;
  case 8:  
    custom8(x);
    break;
  case 9:  
    custom9(x);
    break;

  }

}

void checkUp()
{
  up_buttonState = digitalRead(Up_buttonPin);

  // compare the buttonState to its previous state
  if (up_buttonState != up_lastButtonState) {
    // if the state has changed, increment the counter
    if (up_buttonState == LOW) {
        bPress = true;
      // if the current state is HIGH then the button went from off to on:
      buttonPushCounter++;
      Serial.println("on");
      Serial.print("number of button pushes: ");
      Serial.println(buttonPushCounter);
    } else {
      // if the current state is LOW then the button went from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  up_lastButtonState = up_buttonState;
}
void checkDown()
{
  down_buttonState = digitalRead(Down_buttonPin);

  // compare the buttonState to its previous state
  if (down_buttonState != down_lastButtonState) {
    // if the state has changed, increment the counter
    if (down_buttonState == LOW) {
        bPress = true;
      // if the current state is HIGH then the button went from off to on:
      buttonPushCounter--;
     
      Serial.println("on");
      Serial.print("number of button pushes: ");
      Serial.println(buttonPushCounter);
    } else {
      // if the current state is LOW then the button went from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  down_lastButtonState = down_buttonState;
}

Matt, you need to edit those posts and add the code tags

Like this

Very hard to read now...

To add the servo to the code that you posted.
Include the servo library

#include <Servo.h>

Create a servo object

Servo servo;

In setup(), attach the servo.

servo.attach(4);  // or any pin that you want

in the displayNumber() function add:

servo.write(buttonPushCounter);

I connected up 2 buttons and a servo to my Uno and modified your code as above. It works. Additionally I had to use a different LDC I2C library because I don't have the one that you used. Just uncomment the LiquidCrystal library stuff and comment or remove the hd44780 library stuff. Better yet, install the hd44780 library because, in my opinion, it is a better library.

#include <Wire.h>
//#include <LiquidCrystal_I2C.h>
#include <hd44780.h>                       // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h>
#include <Servo.h>

//LiquidCrystal_I2C lcd(0x3F, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
hd44780_I2Cexp lcd;
Servo servo;

const int LCD_COLS = 16;
const int LCD_ROWS = 2;

int counter = 0;

// this constant won't change:
const int  Up_buttonPin   = 2;    // the pin that the pushbutton is attached to
const int  Down_buttonPin = 3;

// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
int up_buttonState = 0;         // current state of the up button
int up_lastButtonState = 0;     // previous state of the up button

int down_buttonState = 0;         // current state of the up button
int down_lastButtonState = 0;     // previous state of the up button
bool bPress = false;

byte LT[8] =
{

   B00111,
   B01111,
   B11111,
   B11111,
   B11111,
   B11111,
   B11111,
   B11111
};
byte UB[8] =
{
   B11111,
   B11111,
   B11111,
   B00000,
   B00000,
   B00000,
   B00000,
   B00000
};
byte RT[8] =
{

   B11100,
   B11110,
   B11111,
   B11111,
   B11111,
   B11111,
   B11111,
   B11111
};
byte LL[8] =
{


   B11111,
   B11111,
   B11111,
   B11111,
   B11111,
   B11111,
   B01111,
   B00111
};
byte LB[8] =
{
   B00000,
   B00000,
   B00000,
   B00000,
   B00000,
   B11111,
   B11111,
   B11111
};
byte LR[8] =
{


   B11111,
   B11111,
   B11111,
   B11111,
   B11111,
   B11111,
   B11110,
   B11100
};
byte MB[8] =
{
   B11111,
   B11111,
   B11111,
   B00000,
   B00000,
   B00000,
   B11111,
   B11111
};
byte block[8] =
{
   B11111,
   B11111,
   B11111,
   B11111,
   B11111,
   B11111,
   B11111,
   B11111
};

void setup()
{
   pinMode( Up_buttonPin , INPUT_PULLUP);
   pinMode( Down_buttonPin , INPUT_PULLUP);
    servo.attach(4);
   //lcd.init();                      // initialize the lcd
   lcd.begin(LCD_COLS, LCD_ROWS);
   
   lcd.createChar(0, LT);
   lcd.createChar(1, UB);
   lcd.createChar(2, RT);
   lcd.createChar(3, LL);
   lcd.createChar(4, LB);
   lcd.createChar(5, LR);
   lcd.createChar(6, MB);
   lcd.createChar(7, block);

   // Print a message to the LCD.
   lcd.backlight();

   lcd.clear();

   displayNumber();

}

void printNumber(int val)
{

   int col = 5;

   if ( val >= 10)
   {
      printDigits(val / 10, col);
      printDigits(val % 10, col + 4);
   }
   else
   {
      printDigits(val, col);
   }
}

void loop()
{
   checkUp();
   checkDown();

   if ( bPress)
   {
      bPress = false;
      displayNumber();
   }
}
void displayNumber()
{

   lcd.clear();
   lcd.setCursor(0, 0);
   lcd.print("Vol:");
   printNumber( buttonPushCounter);
   servo.write(buttonPushCounter);
}
void custom0(int x)
{

   lcd.setCursor(x, 0);
   lcd.write(0);
   lcd.write(1);
   lcd.write(2);
   lcd.setCursor(x, 1);
   lcd.write(3);
   lcd.write(4);
   lcd.write(5);
}

void custom1(int x)
{
   lcd.setCursor(x, 0);
   lcd.write(1);
   lcd.write(2);
   lcd.print(" ");
   lcd.setCursor(x, 1);
   lcd.write(4);
   lcd.write(7);
   lcd.write(4);
}

void custom2(int x)
{
   lcd.setCursor(x, 0);
   lcd.write(6);
   lcd.write(6);
   lcd.write(2);
   lcd.setCursor(x, 1);
   lcd.write(3);
   lcd.write(4);
   lcd.write(4);
}

void custom3(int x)
{
   lcd.setCursor(x, 0);
   lcd.write(6);
   lcd.write(6);
   lcd.write(2);
   lcd.setCursor(x, 1);
   lcd.write(4);
   lcd.write(4);
   lcd.write(5);
}

void custom4(int x)
{
   lcd.setCursor(x, 0);
   lcd.write(3);
   lcd.write(4);
   lcd.write(7);
   lcd.setCursor(x, 1);
   lcd.print(" ");
   lcd.print(" ");
   lcd.write(7);
}

void custom5(int x)
{
   lcd.setCursor(x, 0);
   lcd.write(3);
   lcd.write(6);
   lcd.write(6);
   lcd.setCursor(x, 1);
   lcd.write(4);
   lcd.write(4);
   lcd.write(5);
}

void custom6(int x)
{
   lcd.setCursor(x, 0);
   lcd.write(0);
   lcd.write(6);
   lcd.write(6);
   lcd.setCursor(x, 1);
   lcd.write(3);
   lcd.write(4);
   lcd.write(5);
}

void custom7(int x)
{
   lcd.setCursor(x, 0);
   lcd.write(1);
   lcd.write(1);
   lcd.write(2);
   lcd.setCursor(x, 1);
   lcd.print(" ");
   lcd.print(" ");
   lcd.write(7);
}

void custom8(int x)
{
   lcd.setCursor(x, 0);
   lcd.write(0);
   lcd.write(6);
   lcd.write(2);
   lcd.setCursor(x, 1);
   lcd.write(3);
   lcd.write(4);
   lcd.write(5);
}

void custom9(int x)
{

   lcd.setCursor(x, 0);
   lcd.write(0);
   lcd.write(6);
   lcd.write(2);
   lcd.setCursor(x, 1);
   lcd.print(" ");
   lcd.print(" ");
   lcd.write(7);

}
void printDigits(int digits, int x)
{
   // utility function for digital clock display: prints preceding colon and leading 0

   switch (digits)
   {
      case 0:
         custom0(x);
         break;
      case 1:
         custom1(x);
         break;
      case 2:
         custom2(x);
         break;
      case 3:
         custom3(x);
         break;
      case 4:
         custom4(x);
         break;
      case 5:
         custom5(x);
         break;
      case 6:
         custom6(x);
         break;
      case 7:
         custom7(x);
         break;
      case 8:
         custom8(x);
         break;
      case 9:
         custom9(x);
         break;
   }
}

void checkUp()
{
   up_buttonState = digitalRead(Up_buttonPin);

   // compare the buttonState to its previous state
   if (up_buttonState != up_lastButtonState)
   {
      // if the state has changed, increment the counter
      if (up_buttonState == LOW)
      {
         bPress = true;
         // if the current state is HIGH then the button went from off to on:
         buttonPushCounter++;
         Serial.println("on");
         Serial.print("number of button pushes: ");
         Serial.println(buttonPushCounter);
      }
      else
      {
         // if the current state is LOW then the button went from on to off:
         Serial.println("off");
      }
      // Delay a little bit to avoid bouncing
      delay(50);
   }
   // save the current state as the last state, for next time through the loop
   up_lastButtonState = up_buttonState;
}

void checkDown()
{
   down_buttonState = digitalRead(Down_buttonPin);

   // compare the buttonState to its previous state
   if (down_buttonState != down_lastButtonState)
   {
      // if the state has changed, increment the counter
      if (down_buttonState == LOW)
      {
         bPress = true;
         // if the current state is HIGH then the button went from off to on:
         buttonPushCounter--;

         Serial.println("on");
         Serial.print("number of button pushes: ");
         Serial.println(buttonPushCounter);
      }
      else
      {
         // if the current state is LOW then the button went from on to off:
         Serial.println("off");
      }
      // Delay a little bit to avoid bouncing
      delay(50);
   }
   // save the current state as the last state, for next time through the loop
   down_lastButtonState = down_buttonState;
}

I raced KT100 (Walbro weed eater carb) a while back and from my experience I think that 1 degree adjustment may be a bit fine. If I remember right I did about 1/8-1/4 turn lean for the long straight and back 1/8-1/4 turn rich for the infield (by hand, of course).

Thank you for the info. Good to hear you understand the application. Let me have a play and i'll be back if I still have no love.

This seems to be worse. now I get an error "
exit status 1
Error compiling for board Arduino/Genuino Uno." :frowning:

There must be more to the error message. We can't help without the entire message. If that is really all there is, go to File, Preferences and enable verbose output for compiling and re-compile. There is a button in the lower right of the IDE window that says "Copy error message". Copy the message and paste into code tags in a new post.

If you modified the code that I posted, please post the new code (in code tags, please).
I know that my code compiles and works because I tested it.

I assume I don't have the library installed correctly?

Arduino: 1.8.5 (Windows 8.1), Board: "Arduino/Genuino Uno"

C:\Users\Matthewwaye\Documents\Arduino\sketch_jul05a\sketch_jul05a.ino:4:43: fatal error: hd44780ioClass/hd44780_I2Cexp.h: No such file or directory

 #include <hd44780ioClass/hd44780_I2Cexp.h>

                                           ^

compilation terminated.

exit status 1
Error compiling for board Arduino/Genuino Uno.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

MattheWaye:
I assume I don't have the library installed correctly?

I presume you are trying to merge two programs that each worked separately. If you are using that library in one of the programs then it must be installed correctly.

...R

Getting more and more lost :frowning:

Arduino: 1.8.5 (Windows 8.1), Board: "Arduino/Genuino Uno"

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Matthewwaye\Documents\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10805 -build-path C:\Users\MATTHE~1\AppData\Local\Temp\arduino_build_375687 -warnings=none -build-cache C:\Users\MATTHE~1\AppData\Local\Temp\arduino_cache_542974 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\Matthewwaye\Documents\Arduino\sketch_jul05c\sketch_jul05c.ino
C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\Matthewwaye\Documents\Arduino\libraries -fqbn=arduino:avr:uno -ide-version=10805 -build-path C:\Users\MATTHE~1\AppData\Local\Temp\arduino_build_375687 -warnings=none -build-cache C:\Users\MATTHE~1\AppData\Local\Temp\arduino_cache_542974 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\Matthewwaye\Documents\Arduino\sketch_jul05c\sketch_jul05c.ino
Using board 'uno' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Using core 'arduino' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Detecting libraries used...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\MATTHE~1\AppData\Local\Temp\arduino_build_375687\sketch\sketch_jul05c.ino.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "C:\Users\MATTHE~1\AppData\Local\Temp\arduino_build_375687\sketch\sketch_jul05c.ino.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire\src" "C:\Users\MATTHE~1\AppData\Local\Temp\arduino_build_375687\sketch\sketch_jul05c.ino.cpp" -o "C:\Users\MATTHE~1\AppData\Local\Temp\arduino_build_375687\preproc\ctags_target_for_gcc_minus_e.cpp"
C:\Users\Matthewwaye\Documents\Arduino\sketch_jul05c\sketch_jul05c.ino:3:66: fatal error: hd44780.h: No such file or directory

 #include <hd44780.h>                       // main hd44780 header

                                                                  ^

compilation terminated.

Using library Wire at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire 
exit status 1
Error compiling for board Arduino/Genuino Uno.

I assume I don't have the library installed correctly?

The hd44780 library can be installed through the Library Manager. In the IDE go to Sketch, Include Libraries, Manage Libraries. In the Library Manager window, in the Topic dropdown, choose Display and type "hd44780" (without quotes) in the Filter your search textbox. You may need to scroll down to hd44780 by Bill Perry. Click on that and click "install".

Or, like I said in reply #9, uncomment the LiquidCrystal library stuff and comment or remove the hd44780 library stuff.

If you still can't get the code to compile, post the code.

Thank you I must have downloaded the wrong hd44780 Yes the one from Bill will now let me verify the code.

Cool, does the code do what you want?

Perfect the counter is working correctly. Servo is unresponsive. Where do I add the code to have the servo move incrementally with the counter on the screen?
Is there a way to post an image on this forum?

#include <Wire.h>
//#include <LiquidCrystal_I2C.h>
#include <hd44780.h>                       // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h>
#include <Servo.h>

//LiquidCrystal_I2C lcd(0x3F, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
hd44780_I2Cexp lcd;
Servo servo;

const int LCD_COLS = 16;
const int LCD_ROWS = 2;

int counter = 0;

// this constant won't change:
const int  Up_buttonPin   = 2;    // the pin that the pushbutton is attached to
const int  Down_buttonPin = 3;

// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
int up_buttonState = 0;         // current state of the up button
int up_lastButtonState = 0;     // previous state of the up button

int down_buttonState = 0;         // current state of the up button
int down_lastButtonState = 0;     // previous state of the up button
bool bPress = false;

byte LT[8] =
{

   B00111,
   B01111,
   B11111,
   B11111,
   B11111,
   B11111,
   B11111,
   B11111
};
byte UB[8] =
{
   B11111,
   B11111,
   B11111,
   B00000,
   B00000,
   B00000,
   B00000,
   B00000
};
byte RT[8] =
{

   B11100,
   B11110,
   B11111,
   B11111,
   B11111,
   B11111,
   B11111,
   B11111
};
byte LL[8] =
{


   B11111,
   B11111,
   B11111,
   B11111,
   B11111,
   B11111,
   B01111,
   B00111
};
byte LB[8] =
{
   B00000,
   B00000,
   B00000,
   B00000,
   B00000,
   B11111,
   B11111,
   B11111
};
byte LR[8] =
{


   B11111,
   B11111,
   B11111,
   B11111,
   B11111,
   B11111,
   B11110,
   B11100
};
byte MB[8] =
{
   B11111,
   B11111,
   B11111,
   B00000,
   B00000,
   B00000,
   B11111,
   B11111
};
byte block[8] =
{
   B11111,
   B11111,
   B11111,
   B11111,
   B11111,
   B11111,
   B11111,
   B11111
};

void setup()
{
   pinMode( Up_buttonPin , INPUT_PULLUP);
   pinMode( Down_buttonPin , INPUT_PULLUP);
    servo.attach(4);
   //lcd.init();                      // initialize the lcd
   lcd.begin(LCD_COLS, LCD_ROWS);
   
   lcd.createChar(0, LT);
   lcd.createChar(1, UB);
   lcd.createChar(2, RT);
   lcd.createChar(3, LL);
   lcd.createChar(4, LB);
   lcd.createChar(5, LR);
   lcd.createChar(6, MB);
   lcd.createChar(7, block);

   // Print a message to the LCD.
   lcd.backlight();

   lcd.clear();

   displayNumber();

}

void printNumber(int val)
{

   int col = 5;

   if ( val >= 10)
   {
      printDigits(val / 10, col);
      printDigits(val % 10, col + 4);
   }
   else
   {
      printDigits(val, col);
   }
}

void loop()
{
   checkUp();
   checkDown();

   if ( bPress)
   {
      bPress = false;
      displayNumber();
   }
}
void displayNumber()
{

   lcd.clear();
   lcd.setCursor(0, 0);
   lcd.print("Vol:");
   printNumber( buttonPushCounter);
   servo.write(buttonPushCounter);
}
void custom0(int x)
{

   lcd.setCursor(x, 0);
   lcd.write(0);
   lcd.write(1);
   lcd.write(2);
   lcd.setCursor(x, 1);
   lcd.write(3);
   lcd.write(4);
   lcd.write(5);
}

void custom1(int x)
{
   lcd.setCursor(x, 0);
   lcd.write(1);
   lcd.write(2);
   lcd.print(" ");
   lcd.setCursor(x, 1);
   lcd.write(4);
   lcd.write(7);
   lcd.write(4);
}

void custom2(int x)
{
   lcd.setCursor(x, 0);
   lcd.write(6);
   lcd.write(6);
   lcd.write(2);
   lcd.setCursor(x, 1);
   lcd.write(3);
   lcd.write(4);
   lcd.write(4);
}

void custom3(int x)
{
   lcd.setCursor(x, 0);
   lcd.write(6);
   lcd.write(6);
   lcd.write(2);
   lcd.setCursor(x, 1);
   lcd.write(4);
   lcd.write(4);
   lcd.write(5);
}

void custom4(int x)
{
   lcd.setCursor(x, 0);
   lcd.write(3);
   lcd.write(4);
   lcd.write(7);
   lcd.setCursor(x, 1);
   lcd.print(" ");
   lcd.print(" ");
   lcd.write(7);
}

void custom5(int x)
{
   lcd.setCursor(x, 0);
   lcd.write(3);
   lcd.write(6);
   lcd.write(6);
   lcd.setCursor(x, 1);
   lcd.write(4);
   lcd.write(4);
   lcd.write(5);
}

void custom6(int x)
{
   lcd.setCursor(x, 0);
   lcd.write(0);
   lcd.write(6);
   lcd.write(6);
   lcd.setCursor(x, 1);
   lcd.write(3);
   lcd.write(4);
   lcd.write(5);
}

void custom7(int x)
{
   lcd.setCursor(x, 0);
   lcd.write(1);
   lcd.write(1);
   lcd.write(2);
   lcd.setCursor(x, 1);
   lcd.print(" ");
   lcd.print(" ");
   lcd.write(7);
}

void custom8(int x)
{
   lcd.setCursor(x, 0);
   lcd.write(0);
   lcd.write(6);
   lcd.write(2);
   lcd.setCursor(x, 1);
   lcd.write(3);
   lcd.write(4);
   lcd.write(5);
}

void custom9(int x)
{

   lcd.setCursor(x, 0);
   lcd.write(0);
   lcd.write(6);
   lcd.write(2);
   lcd.setCursor(x, 1);
   lcd.print(" ");
   lcd.print(" ");
   lcd.write(7);

}
void printDigits(int digits, int x)
{
   // utility function for digital clock display: prints preceding colon and leading 0

   switch (digits)
   {
      case 0:
         custom0(x);
         break;
      case 1:
         custom1(x);
         break;
      case 2:
         custom2(x);
         break;
      case 3:
         custom3(x);
         break;
      case 4:
         custom4(x);
         break;
      case 5:
         custom5(x);
         break;
      case 6:
         custom6(x);
         break;
      case 7:
         custom7(x);
         break;
      case 8:
         custom8(x);
         break;
      case 9:
         custom9(x);
         break;
   }
}

void checkUp()
{
   up_buttonState = digitalRead(Up_buttonPin);

   // compare the buttonState to its previous state
   if (up_buttonState != up_lastButtonState)
   {
      // if the state has changed, increment the counter
      if (up_buttonState == LOW)
      {
         bPress = true;
         // if the current state is HIGH then the button went from off to on:
         buttonPushCounter++;
         Serial.println("on");
         Serial.print("number of button pushes: ");
         Serial.println(buttonPushCounter);
      }
      else
      {
         // if the current state is LOW then the button went from on to off:
         Serial.println("off");
      }
      // Delay a little bit to avoid bouncing
      delay(50);
   }
   // save the current state as the last state, for next time through the loop
   up_lastButtonState = up_buttonState;
}

void checkDown()
{
   down_buttonState = digitalRead(Down_buttonPin);

   // compare the buttonState to its previous state
   if (down_buttonState != down_lastButtonState)
   {
      // if the state has changed, increment the counter
      if (down_buttonState == LOW)
      {
         bPress = true;
         // if the current state is HIGH then the button went from off to on:
         buttonPushCounter--;

         Serial.println("on");
         Serial.print("number of button pushes: ");
         Serial.println(buttonPushCounter);
      }
      else
      {
         // if the current state is LOW then the button went from on to off:
         Serial.println("off");
      }
      // Delay a little bit to avoid bouncing
      delay(50);
   }
   // save the current state as the last state, for next time through the loop
   down_lastButtonState = down_buttonState;
}