how could i combine these two programs together

hey everyone i'm trying to combine these two programs together to make a quadrupedal obstacle avoiding robot I've tried if statements and looked on internet and find anything close to what i'm trying to achieve.
but no such luck.

sketch_may17a.ino (1.6 KB)

q-ped.ino (382 Bytes)

This Simple Merge Demo may give you some ideas.

You must make sure that the programs are not both trying to use the same piece of hardware - such as an I/O pin.

...R

A good start would be to describe to yourself how you want the resulting program to behave, then allocate pins for servos, buttons and leds.

The two source files should provide you with good examples of how servos are interfaced. Reading and writing pins is also exemplified, and that's all you need to read buttons and control leds.

The example "button program" controls a "third" servo, with regards to the other program, which operates two servos. Is this what you want?

:slight_smile:

What the heck is someone ever ginna awnser mine?

I'm trying to use two ultrasonic sensors and two servos and the two servos will sweep back and fourth.

maduffa:
I'm trying to use two ultrasonic sensors and two servos and the two servos will sweep back and fourth.

Okay, that's a good start. So you need your program to:

  • include Servo library
  • create two Servo objects, deciding what pins each will use
  • add appropriate code to the setup() function (code examples for servos are easy to find)
  • create a main loop that moves the two servos as you'd like

Then you add the functionality of the ultrasonic sensors (sonars). Example code for how to activate one and get a return value back, is easily available on the internet.

  • create a function, say callSonar() with parameters indicating the pins of the sonar in question
  • add global defines and/or variables, and add initialization of pin modes in your setup function
  • add calls to your sonar function, with the actual pins of first one then the other sonar
  • user Serial.println() to log results to the "Serial Monitor", so you see what's happening.

test, modify, test, modify, ...

:slight_smile: