this codes involve 2 DC motor and a brushless. the problem came if i combine both coding use copy&paste. my DC motor not responding to the remote control and only the brushless that functioning.
BRUSHLESS_2.ino (848 Bytes)
Lab_5__4.0.ino (2.39 KB)
this codes involve 2 DC motor and a brushless. the problem came if i combine both coding use copy&paste. my DC motor not responding to the remote control and only the brushless that functioning.
BRUSHLESS_2.ino (848 Bytes)
Lab_5__4.0.ino (2.39 KB)
Maybe this Simple Merge Demo will give you some ideas.
For short programs please include them in your post between [code] [/code] tags so we don't have to download them and your code looks like thisand is easy to copy to a text editor
...R
Combining two codes starts with knowing what you want the resulting program to do. If you know that, you forgot to share it.
If you don't, you might as well forget it.
What's the difference between 'DC motor' and 'brushless'? Your brushless run on AC or applesauce or?
FIRST CODE
#include <Servo.h>
#include<avr/sleep.h>
Servo myservo;
float angle =0;
int button_A = 8;
int button_B = 13;
int button_C = 4;
int button_D = 12;
int enablePin1 =7;
int motor1Pin1 = 6;
int motor1Pin2 = 5;
int enablePin2 =11;
int motor2Pin1 = 10;
int motor2Pin2 = 3;
int position=0;
void setup() {
pinMode(button_A, INPUT);
pinMode(button_B, INPUT);
pinMode(button_C, INPUT);
pinMode(button_D,INPUT);
pinMode(motor1Pin1, OUTPUT);
pinMode(motor1Pin2, OUTPUT);
pinMode(motor2Pin1, OUTPUT);
pinMode(motor2Pin2, OUTPUT);
pinMode(enablePin1, OUTPUT);
pinMode(enablePin2, OUTPUT);
}
void forward()
{
digitalWrite (enablePin1 ,HIGH);
digitalWrite(motor1Pin1, HIGH);
digitalWrite(motor1Pin2, LOW);
digitalWrite (enablePin2 ,HIGH);
digitalWrite(motor2Pin2, HIGH);
digitalWrite(motor2Pin1, LOW);
}
void loop(){
if (digitalRead(button_A) == HIGH && digitalRead(button_B) == HIGH) {
digitalWrite (enablePin1 ,LOW);
digitalWrite (enablePin2 ,LOW);
}
else if (digitalRead(button_A) == HIGH && digitalRead(button_B) == LOW)
{
digitalWrite (enablePin1 ,HIGH);
digitalWrite(motor1Pin1, HIGH);
digitalWrite(motor1Pin2, LOW);
}
else if (digitalRead(button_A) == LOW && digitalRead(button_B) == HIGH)
{
digitalWrite (enablePin2 ,HIGH);
digitalWrite(motor2Pin2, HIGH);
digitalWrite(motor2Pin1, LOW);
}
else if (digitalRead(button_A) == LOW && digitalRead(button_B) == LOW)
{
digitalWrite (enablePin1 ,HIGH);
digitalWrite(motor1Pin1, HIGH);
digitalWrite(motor1Pin2, LOW);
digitalWrite (enablePin2 ,HIGH);
digitalWrite(motor2Pin2, HIGH);
digitalWrite(motor2Pin1, LOW);
}
if (digitalRead(button_C) == LOW )
{
for(angle=0;angle<90;angle +=120)
{
myservo.write(angle);
delay(280);
}
for (angle=90;angle>=0;angle-=120)
{
myservo.write(angle);
delay (280);
}
}
if (digitalRead(button_D) == LOW )
forward();
}
SECOND CODE
#include <Servo.h>
Servo esc;
int pos = 0; //Sets position variable
void arm(){
setSpeed(0); //Sets speed variable delay(1000);
}
void setSpeed(int speed){
int angle = map(speed, 0, 100, 0, 180); //Sets servo positions to different speeds ESC1.write(angle);
esc.write(angle);
}
void setup() {
esc.attach(9); //Adds ESC to certain pin. arm();
}
void loop() {
int speed; //Implements speed variable
for(speed = 0; speed <= 70; speed += 5) { //Cycles speed up to 70% power for 1 second
setSpeed(speed); //Creates variable for speed to be used in in for loop
delay(1000);
}
delay(4000); //Stays on for 4 seconds
for(speed = 70; speed > 0; speed -= 5) { // Cycles speed down to 0% power for 1 second
setSpeed(speed); delay(1000);
}
setSpeed(0); //Sets speed variable to zero no matter what
delay(1000); //Turns off for 1 second
}
Is there a question?
Specification?
Code tags?
Please modify your posts and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum Your code is too long for me to study quickly without copying to a text editor.
And post your attempt at the merged program.
Also, you need to tell us what each program is intended to do and what, exactly, happens when you run the merged program.
The use of the delay() function may cause a problem. Have a look at how millis() is used to manage timing without blocking in several things at a time
...R
Here is the problem
this codes involve 2 DC motor and a brushless. the problem came if i combine both coding use copy&paste. my DC motor not responding to the remote control and only the brushless that functioning.
You'll probably have to lose the calls to delay.
You'll also have to stop cross-posting.
amirulbuang:
Here is the problem
this codes involve 2 DC motor and a brushless. the problem came if i combine both coding use copy&paste. my DC motor not responding to the remote control and only the brushless that functioning.
NO. Here is the problem ... you have not studied Reply #7 and followed the advice in it.
...R
Robin2:
NO. Here is the problem ... you have not studied Reply #7 and followed the advice in it....R
Or reply #2.
amirulbuang:
Here is the problem
this codes involve 2 DC motor and a brushless. the problem came if i combine both coding use copy&paste. my DC motor not responding to the remote control and only the brushless that functioning.
It will help if you post the merged code.
merged code
#include <Servo.h>
#include<avr/sleep.h>
Servo myservo;
Servo esc;
float angle =0;
int button_A = 8;
int button_B = 13;
int button_C = 4;
int button_D = 12;
int enablePin1 =7;
int motor1Pin1 = 6;
int motor1Pin2 = 5;
int enablePin2 =11;
int motor2Pin1 = 10;
int motor2Pin2 = 3;
int position=0;
int pos = 0; //Sets position variable
void arm(){
setSpeed(0); //Sets speed variable delay(1000);
}
void setSpeed(int speed){
int angle = map(speed, 0, 100, 0, 180); //Sets servo positions to different speeds ESC1.write(angle);
esc.write(angle);
}
void setup() {
esc.attach(9);
pinMode(button_A, INPUT);
pinMode(button_B, INPUT);
pinMode(button_C, INPUT);
pinMode(button_D,INPUT);
pinMode(motor1Pin1, OUTPUT);
pinMode(motor1Pin2, OUTPUT);
pinMode(motor2Pin1, OUTPUT);
pinMode(motor2Pin2, OUTPUT);
pinMode(enablePin1, OUTPUT);
pinMode(enablePin2, OUTPUT);
}
void forward()
{
digitalWrite (enablePin1 ,HIGH);
digitalWrite(motor1Pin1, HIGH);
digitalWrite(motor1Pin2, LOW);
digitalWrite (enablePin2 ,HIGH);
digitalWrite(motor2Pin2, HIGH);
digitalWrite(motor2Pin1, LOW);
}
void loop(){
if (digitalRead(button_A) == HIGH && digitalRead(button_B) == HIGH) {
digitalWrite (enablePin1 ,LOW);
digitalWrite (enablePin2 ,LOW);
}
else if (digitalRead(button_A) == HIGH && digitalRead(button_B) == LOW)
{
digitalWrite (enablePin1 ,HIGH);
digitalWrite(motor1Pin1, HIGH);
digitalWrite(motor1Pin2, LOW);
}
else if (digitalRead(button_A) == LOW && digitalRead(button_B) == HIGH)
{
digitalWrite (enablePin2 ,HIGH);
digitalWrite(motor2Pin2, HIGH);
digitalWrite(motor2Pin1, LOW);
}
else if (digitalRead(button_A) == LOW && digitalRead(button_B) == LOW)
{
digitalWrite (enablePin1 ,HIGH);
digitalWrite(motor1Pin1, HIGH);
digitalWrite(motor1Pin2, LOW);
digitalWrite (enablePin2 ,HIGH);
digitalWrite(motor2Pin2, HIGH);
digitalWrite(motor2Pin1, LOW);
}
if (digitalRead(button_C) == LOW )
{
for(angle=0;angle<90;angle +=120)
{
myservo.write(angle);
delay(280);
}
for (angle=90;angle>=0;angle-=120)
{
myservo.write(angle);
delay (280);
}
}
if (digitalRead(button_D) == LOW )
forward();
int speed; //Implements speed variable
for(speed = 0; speed <= 70; speed += 5) { //Cycles speed up to 70% power for 1 second
setSpeed(speed); //Creates variable for speed to be used in in for loop
delay(1000);
}
delay(4000); //Stays on for 4 seconds
for(speed = 70; speed > 0; speed -= 5) { // Cycles speed down to 0% power for 1 second
setSpeed(speed); delay(1000);
}
setSpeed(0); //Sets speed variable to zero no matter what
delay(1000); //Turns off for 1 second
}
merged code
And?
(remember to use code tags when posting code)
@amirulbuang, I am not going to make any further attempt to help until you update your posts with code in them as I suggested in Reply #7
Help us to help you.
...R
int angle = map(speed, 0, 100, 0, 180); //Sets servo positions to different speeds ESC1.write(angle);
That's a pretty expensive way to multiply by 1.8.
There are STILL NO requirements. Like Robin2, I'm done.