Did you try the simple things first, and combine the two by copying both setup()s into setup() of a third sketch, ditto the loop()s, and ditto all the stuff outside of both into the are outside both in the third sketch?
For what it's worth, here is what I get when I do that, with the major caveat that I can't even compile it since I don't have that LCD library installed. And if I did, It couldn't test it since I don't have a continuous servo with an encoder.
But maybe it's a start? It's literally a copy/paste from your sketches into a third one. Heed what b707 said, though.
// https://forum.arduino.cc/t/combining-2-working-sketches-together-components-used-dc-motor-push-button-i2c-display-rotary-encoder/1011687
// combined code from above forum thread
// uncompiled (I don't have the LCD library
// and even if it was compiled, it would be untested due to not having servo and encoder
// but maybe it's a start?
#include <Servo.h> // start of first code for dc motor
Servo myservo; // create servo object to control a servo
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Encoder.h>
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display
Encoder myEnc(11, 10);
int pos = 0; // variable to store the servo position
int pulse = 1500;
void setup() {
pinMode(2, INPUT_PULLUP); // enable internal pull-up
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
Serial.begin(9600);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo.writeMicroseconds(1500);
Serial.println("started!");
Serial.println("Encoder Test");
pinMode(12, INPUT);
lcd.init(); // initialize the lcd
lcd.init();
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(1, 0);
lcd.print("Tether spool v1.0");
lcd.setCursor(1, 1);
lcd.print("Hi Gavin!");
delay(500);
lcd.clear();
}
long oldPosition = -999;
long newPosition = 0;
void loop() {
if (digitalRead(4) == 0) //front
{
Serial.println("Forward Pushed!");
pulse = 2000;
while (digitalRead(4) == 0);
Serial.println("Forward Released!");
delay(100);
}
if (digitalRead(3) == 0) //back
{
Serial.println("Stop Pushed!");
pulse = 1500;
while (digitalRead(3) == 0);
Serial.println("Stop Released!");
delay(100);
}
if (digitalRead(2) == 0) //back
{
Serial.println("Back Pushed!");
pulse = 1000;
while (digitalRead(2) == 0);
Serial.println("Back Released!");
delay(100);
}
else
{
myservo.writeMicroseconds(pulse);
}
long newPosition = myEnc.read() / 4;
if (newPosition != oldPosition)
{
oldPosition = newPosition;
Serial.println(newPosition);
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("wire length:");
lcd.setCursor(1, 1);
lcd.print(newPosition);
lcd.setCursor(12, 1);
lcd.print("mtr");
}
}// loop
2 things to think about when writing code that is going to be merged
encapsulation: make the code run in a complete way without global variables trying to keep variables una tight scope. This means one code will less likely interfere with another when merged by eg having two variables with the same name in the same scope.
speed; let the code loop as fast as possible. Remove delays. Rely on a fast loop to check states regularly rather than to wait for a state to change. This means a delay in one code will not prevent another from working properly.