Need help in arduino coding of a project?

I have this code but i would like to use simple DC motor except continuous rotation servos

[code]

/*

Telepresence Robot

Code for controlling the robot through DTMF tones made by the smartphone.

*/

// Include the necessary libraries for DTMF shield and servos

#include "dtmf.h"

#include <Servo.h>

// Enable the DFRobot DTMF board pins

DTMF dtmf;

// Variable for storing DTMF codes

int myDtmf;

// Tell the Arduino there is a standard servo

Servo StandardServo1;

// Tell the Arduino there are to continuous servos

Servo ContinuousServo1;

Servo ContinuousServo2;

//variable to set the camera. Set to a neutral position by default.

int cameraPosition = 70;

void setup(){

// Attach the standard servo to pin 5

StandardServo1.attach(5);

// Attach the continuous servos to pins 6 and 7

ContinuousServo1.attach(6);

ContinuousServo2.attach(7);

//Set default position for the standard servo

StandardServo1.write(cameraPosition); // tell servo to go to the value of the variable cameraPosition

delay(2000); // pause for 2 seconds

//Pause the continuous rotation servos

ContinuousServo1.write(94);

ContinuousServo2.write(94);

Serial.begin(9600);

}

void loop(){

// Read the incoming DTMF codes using a function from the DTMF library.

// And store it to the variable myDtmf

myDtmf = dtmf.getDTMF();

// Now, check to see if the myDtmf variable matches any of these numbers

// If it does, perform the function associated with that number

// If the function involves driving, the "driving" boolean is set to true.

// Otherwise, the driving boolean is set to false.

switch(myDtmf){

case 2:

forward();

break;

case 8:

backward();

break;

case 4:

left();

break;

case 6:

right();

break;

case 7:

tiltUp();

break;

case 9:

tiltDown();

break;

default:

stopDriving();

break;

}

// Pause for a fraction of a second

// This is necessary to slow down the code just a smidge for the tilt function to work

// Don't ask me why. Sometimes the code just needs a pause.

delay(10);

}

///////////////////

// TILT FUNTIONS //

///////////////////

void tiltUp(){

// Check to see if the camera position is less than 120, and if it is...

if(cameraPosition < 120){

// increase the camera position by 1

cameraPosition = cameraPosition + 1;

// tell servo to go to the value of the variable cameraPosition

StandardServo1.write(cameraPosition);

}

}

void tiltDown(){

// Check to see if the camera position is greater than 20, and if it is...

if(cameraPosition > 20){

// decrease the camera position by 1

cameraPosition = cameraPosition - 1;

// tell servo to go to the value of the variable cameraPosition

StandardServo1.write(cameraPosition);

}

}

/////////////////////

// DRIVE FUNCTIONS //

/////////////////////

void stopDriving() {

ContinuousServo1.write(94);

ContinuousServo2.write(94);

}

void forward(){

ContinuousServo1.write(84);

ContinuousServo2.write(104);

}

void backward(){

ContinuousServo1.write(104);

ContinuousServo2.write(84);

}

void right(){

ContinuousServo1.write(104);

ContinuousServo2.write(104);

}

void left(){

ContinuousServo1.write(84);

ContinuousServo2.write(84);

}

[/code]


bekathwia3 months ago

I see that you are using code from the Robots class, which contains code for controlling DC motors:

https://www.instructables.com/lesson/Robot-Brains/...

It's also covered in this lesson of the Arduino class:

https://www.instructables.com/lesson/InputOutput/#...

After reviewing both classes, you should be able to write your own code that is similar to the telepresence robot, but it will be quite different than the servo code (so not quite a "mod and go" solution as you may hope). However it's outside the scope of the classes to write that code for you... go forth and learn, intrepid beginner!