hello guys , i'm making robot ( line car + arm hold and up and down and drop item ) and it's almost done .
i need change controlling in my car and arm to joystick including 2 pots and 4 push button
my car have 4 motors and my arm have two motors , one for up and down and one for hold and drop .
i need use the 2pots to control the 4 motors which make my car in all direction and the 4 push button to control the arm motors .
the push buttons is done coding but the 2 pots i can't and i searched in all codes in the site and others . but i failed to code it .
my auto pilot code was :
int m1_f=2;
int m1_b=3;
int m2_f=4;
int m2_b=5;
int m3_f=6;
int m3_b=7;
int m4_f=8;
int m4_b=9;
int m5_up=22;
int m5_down=23;
int m6_hold=24;
int m6_drop=25;int sen1=10;
int sen2=11;
int sen3=12;
int sen4=13;int sen1_val;
int sen2_val;
int sen3_val;
int sen4_val;void setup() {
// put your setup code here, to run once:
pinMode(m1_f,OUTPUT);
pinMode(m1_b,OUTPUT);
pinMode(m2_f,OUTPUT);
pinMode(m2_b,OUTPUT);
pinMode(m3_f,OUTPUT);
pinMode(m3_b,OUTPUT);
pinMode(m4_f,OUTPUT);
pinMode(m4_b,OUTPUT);
pinMode(m5_up,OUTPUT);
pinMode(m5_down,OUTPUT);
pinMode(m6_hold,OUTPUT);
pinMode(m6_drop,OUTPUT);pinMode(sen1,INPUT);
pinMode(sen2,INPUT);
pinMode(sen3,INPUT);
pinMode(sen4,INPUT);
}void loop() {
// put your main code here, to run repeatedly:}
void robot_fw(){
analogWrite(m1_f , 150);
digitalWrite(m1_b , LOW);
analogWrite(m2_f , 150);
digitalWrite(m2_b , LOW);
analogWrite(m3_f , 150);
digitalWrite(m3_b , LOW);
analogWrite(m4_f , 150);
digitalWrite(m4_b , LOW);}
void robot_bw(){
digitalWrite(m1_f , LOW);
analogWrite(m1_b , 150);
digitalWrite(m2_f , LOW);
analogWrite(m2_b , 150);
digitalWrite(m3_f , LOW);
analogWrite(m3_b , 150);
digitalWrite(m4_f , LOW);
analogWrite(m4_b , 150);}
void robot_left(){
digitalWrite(m1_f , LOW);
analogWrite(m1_b , 150);
analogWrite(m2_f , 150);
digitalWrite(m2_b , LOW);
digitalWrite(m3_f , LOW);
analogWrite(m3_b , 150);
analogWrite(m4_f , 150);
digitalWrite(m4_b , LOW);}
void robot_right(){
analogWrite(m1_f , 150);
digitalWrite(m1_b , LOW);
digitalWrite(m2_f , LOW);
analogWrite(m2_b , 150);
analogWrite(m3_f , 150);
digitalWrite(m3_b , LOW);
digitalWrite(m4_f , LOW);
analogWrite(m4_b , 150);}
void robot_stop(){
digitalWrite(m1_f , LOW);
digitalWrite(m1_b , LOW);
digitalWrite(m2_f , LOW);
digitalWrite(m2_b , LOW);
digitalWrite(m3_f , LOW);
digitalWrite(m3_b , LOW);
digitalWrite(m4_f , LOW);
digitalWrite(m4_b , LOW);}
void robot_arm_hold(){
analogWrite(m6_hold , 150);
digitalWrite(m6_drop , LOW);}
void robot_arm_drop(){
digitalWrite(m6_hold , LOW);
analogWrite(m6_drop , 150);}
void robot_arm_stop(){
digitalWrite(m6_hold , LOW);
digitalWrite(m6_drop , LOW);}
void robot_up(){
digitalWrite(m5_up , HIGH);
digitalWrite(m5_down , LOW);
}void robot_down(){
digitalWrite(m5_up , LOW);
digitalWrite(m5_down , HIGH);
}void auto_pilot(){
sen1_val=digitalRead(sen1);
sen2_val=digitalRead(sen2);
sen3_val=digitalRead(sen3);
sen4_val=digitalRead(sen4);
if (sen1_val==HIGH&&sen2_val==HIGH&&sen3_val==LOW){robot_fw();}
if (sen1_val==HIGH&&sen2_val==LOW&&sen3_val==LOW){robot_left();}
if (sen1_val==LOW&&sen2_val==LOW&&sen3_val==HIGH){robot_right();}
if (sen1_val==LOW&&sen2_val==LOW&&sen3_val==LOW){robot_stop();
delay(4000);
robot_left();
if (sen4_val==HIGH){robot_stop();
delay(1000);
robot_down();
delay(8000);
robot_arm_hold();
delay(3000);
robot_arm_stop();
delay(1000);
robot_up();
delay(3000);
}
robot_left();
}}
and this code which i thought in :
int m1_f=2;
int m1_b=3;
int m2_f=4;
int m2_b=5;
int m3_f=6;
int m3_b=7;
int m4_f=8;
int m4_b=9;const int analoginpin1 = A2;
const int analoginpin2 = A3;int joy_value1 = 0;
int joy_value2 = 0;int motors_value1 = 0;
int motors_value2 = 0;void setup() {
Serial.begin(9600);pinMode(m1_f,OUTPUT);
pinMode(m1_b,OUTPUT);
pinMode(m2_f,OUTPUT);
pinMode(m2_b,OUTPUT);
pinMode(m3_f,OUTPUT);
pinMode(m3_b,OUTPUT);
pinMode(m4_f,OUTPUT);
pinMode(m4_b,OUTPUT);}
void loop() {
joy_value1 = analogRead(analoginpin1);
joy_value2 = analogRead(analoginpin2);motors_value1 = map(joy_value1, 0, 1023, 0, 255);
motors_value2 = map(joy_value2, 0, 1023, 0, 255);analogWrite(here i want to put more than one pin(m1_f + m2_f) , motors_value1);
analogWrite(m1_b , motors_value2);delay(2);
}void robot_fw(){
analogWrite(m1_f,HIGH);
digitalWrite(m1_b,LOW);
analogWrite(m2_f,HIGH);;
digitalWrite(m2_b,LOW);
analogWrite(m3_f,HIGH);
digitalWrite(m3_b,LOW);
analogWrite(m4_f,HIGH);
digitalWrite(m4_b,LOW);}
void robot_bw(){
digitalWrite(m1_f,LOW);
analogWrite(m1_b,HIGH);
digitalWrite(m2_f,LOW);
analogWrite(m2_b,HIGH);
digitalWrite(m3_f,LOW);
analogWrite(m3_b,HIGH);
digitalWrite(m4_f,LOW);
analogWrite(m4_b,HIGH);}
void robot_stop(){
digitalWrite(m1_f,LOW);
digitalWrite(m1_b,LOW);
digitalWrite(m2_f,LOW);
digitalWrite(m2_b,LOW);
digitalWrite(m3_f,LOW);
digitalWrite(m3_b,LOW);
digitalWrite(m4_f,LOW);
digitalWrite(m4_b,LOW);}
void robot_left(){
analogWrite(m1_f,HIGH);
digitalWrite(m1_b,LOW);
digitalWrite(m2_f,LOW);
analogWrite(m2_b,HIGH);
analogWrite(m3_f,HIGH);
digitalWrite(m3_b,LOW);
digitalWrite(m4_f,LOW);
analogWrite(m4_b,HIGH);}
// ???? ????? ??????? ??? ??????
void robot_right(){digitalWrite(m1_f,LOW);
analogWrite(m1_b,HIGH);
analogWrite(m2_f,HIGH);
digitalWrite(m2_b,LOW);
digitalWrite(m3_f,LOW);
analogWrite(m3_b,HIGH);
analogWrite(m4_f,HIGH);
digitalWrite(m4_b,LOW);}
pls i need help fast fast as anyone can ...