Want to combine these sketches

First:


 #include "CytronMotorDriver.h"


// Configure the motor driver.
CytronMD motor1(PWM_DIR, 3, 4);  // PWM 1 = Pin 3, DIR 1 = Pin 4.
CytronMD motor2(PWM_DIR, 9, 10); // PWM 2 = Pin 9, DIR 2 = Pin 10.


// The setup routine runs once when you press reset.
void setup() {
  
}


// The loop routine runs over and over again forever.
void loop() {
  motor1.setSpeed(128);   // Motor 1 runs forward at 50% speed.
  motor2.setSpeed(-128);  // Motor 2 runs backward at 50% speed.
  delay(1000);
  
  motor1.setSpeed(255);   // Motor 1 runs forward at full speed.
  motor2.setSpeed(-255);  // Motor 2 runs backward at full speed.
  delay(1000);

  motor1.setSpeed(0);     // Motor 1 stops.
  motor2.setSpeed(0);     // Motor 2 stops.
  delay(1000);

  motor1.setSpeed(-128);  // Motor 1 runs backward at 50% speed.
  motor2.setSpeed(128);   // Motor 2 runs forward at 50% speed.
  delay(1000);
  
  motor1.setSpeed(-255);  // Motor 1 runs backward at full speed.
  motor2.setSpeed(255);   // Motor 2 runs forward at full speed.
  delay(1000);

  motor1.setSpeed(0);     // Motor 1 stops.
  motor2.setSpeed(0);     // Motor 2 stops.
  delay(1000);
}

second sketche

// include the library code:
#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(8,9,4,5,6,7);

// make some custom characters:
byte heart[8] = {
  0b00000,
  0b01010,
  0b11111,
  0b11111,
  0b11111,
  0b01110,
  0b00100,
  0b00000
};

byte smiley[8] = {
  0b00000,
  0b00000,
  0b01010,
  0b00000,
  0b00000,
  0b10001,
  0b01110,
  0b00000
};

byte frownie[8] = {
  0b00000,
  0b00000,
  0b01010,
  0b00000,
  0b00000,
  0b00000,
  0b01110,
  0b10001
};

byte armsDown[8] = {
  0b00100,
  0b01010,
  0b00100,
  0b00100,
  0b01110,
  0b10101,
  0b00100,
  0b01010
};

byte armsUp[8] = {
  0b00100,
  0b01010,
  0b00100,
  0b10101,
  0b01110,
  0b00100,
  0b00100,
  0b01010
};

void setup() {
  // initialize LCD and set up the number of columns and rows:
  lcd.begin(16, 2);

  // create a new character
  lcd.createChar(0, heart);
  // create a new character
  lcd.createChar(1, smiley);
  // create a new character
  lcd.createChar(2, frownie);
  // create a new character
  lcd.createChar(3, armsDown);
  // create a new character
  lcd.createChar(4, armsUp);

  // set the cursor to the top left
  lcd.setCursor(0, 0);

  // Print a message to the lcd.
  lcd.print(" NELMOW");
  lcd.write(byte(0)); // when calling lcd.write() '0' must be cast as a byte
  lcd.print("NELSONS");
  lcd.write((byte)1);

}

void loop() {
  // read the potentiometer on A0:
  int sensorReading = analogRead(A0);
  // map the result to 200 - 1000:
  int delayTime = map(sensorReading, 0, 1023, 200, 1000);
  // set the cursor to the bottom row, 5th position:
  lcd.setCursor(4, 1);
  // draw the little man, arms down:
  lcd.write(3);
  delay(delayTime);
  lcd.setCursor(4, 1);
  // draw him arms up:
  lcd.write(4);
  delay(delayTime);
}
3rd skecthe
would be to ad 4Ir ( i, e ) 2 up front, 2 in the back for edge  and ultrasonic sensors 1 in the back, 1 front, and 1 on both side. I think that I can only have a code that works for 1 IR and 1 ULtrasonic, then connect the rest in parallel to ad up more. Maybe!`Preformatted text`

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

Well to give a answer with the same shortness as your question:

You simply integrate the commands from setup and the commands from loop.
Check if there are any IO-conflicts and if yes resolve them.

Do you now know how to do it?

Surely not! Even for a real professional embedded software-developper this is not done withing 5 to 15 minutes.

If you refuse to learn some basics about programming you would totally be dependent on somebody's voluntary kindness to write the 10th, the 11th, the 12th modification of your code.

Take a look into this tutorial:

Arduino Programming Course

It is easy to understand and has a good mixture between explaining important concepts and example-codes to get you going. So give it a try and report your opinion about this tutorial.

You are very welcome to ask a lot of questions. Even if it would be hundreds of questions.
But you have to show some own effort. The best way to show some own effort is to make an attempt to proceed.

As a first step read here

a more detailed description is here:

You may find this overwhelming and complicated.

Stay relaxed

whatever your questions might be just ask all the

specific

questions you have
as long as your questions are related to a specific detail

example: the second tutorial in step two

Step Two: Resolve Any Duplicate Function Names By Renaming The Functions

Your question might be "what is a function in programming an arduino?"
This would be a wonderful specific question. For such a question it is almost garanteed that you will get an answer.

contradictory example:
a global question like
Version 1 "can somebody show me how to combine the setups?"
this is the same as asking
Version 2 "can somebody combine the setup-commands for me?"
which would mean
version 3 "can somebody write down all the combined setup-code for me?"

The answer to such a question would be doing all the work for you.
This will not happen.
All three versions are very demanding. The best you can get for such a question are additional links that explain how to merge sketches

You have to make a fundamental decision:

learning the basics about programming and by doing this receive a lot of support from the forum

wasting some time trying to ask "global" questions

buying a ready to use product of the shelf that does the same (fastest way to get your project done)

best regards Stefan

Thanks StefanL38. My younger brother's name like that. i will dig deeper into it.

+1.

Combining Arduino sketches is a very FAQ.

If you google

 combine Arduino sketches

you will get many hits. Give a few of them a few minutes to see if any speak to you in terms you understand.

Since we can only guess, what we guess is that you did not write any of the three sketches, and in all probability have only a casual understanding of them.

This does not make combining them impossible, but a much better approach would be to come to a good understanding of how each works (we can answer questions you will have), plan for the desired functionality you seek in the combination and then... write your own. Sketch.

I don't think you just want a motor to run continuous, for example. Plan now for behaviours you will need that are currently not part of any of the three.

a7

thanks for the help

A few points, after a quick scan of your code:

  • (1st line) defining D4 as 5 and D5 as 4, etc, is very confusing
  • (2nd line) using raw pin numbers in constructors does not help with understanding;e.g. is that 7 a pin number 7, or 7 milliseconds delay. Maybe rename it as D7, pin7, or k_7_mS (ok, I know it's not milliseconds, but a tip for another time), also the other pins too.
  • It looks like pin 9 is used twice; once as a motor PWM, and again as an LCD driver pin. As PWM is more restricted than LCD driver pin, maybe the LCD pin needs changing.

HTH