i want to make robot car keep tennis balls

hello, please help me! i want to make car robot and use 4 relays 4 switches but i have problem about coding program. i created new void but i don't know to to use new void. please help me please i want to make it for my the end project. I'm a student from Thailand. i hope you understand.

my code :

#define SW1_Forward 2 //เดินหน้า
#define SW2_Rigth 3 //เลี้ยวขวา
#define SW3_Reward 4 //ถอยหลัง
#define SW4_Left 5 //เลี้ยวซ้าย
//มอเตอร์ด้านซ้าย
int Relay_1A = 8; //หมุนไปทางซ้าย
int Relay_2A = 9; //หมุนไปทางขวา
//มอเตอร์ด้านขวา
int Relay_1B = 11; //หมุนไปทางซ้าย
int Relay_2B = 12; //หมุนไปทางขวา

int buttonState1_Forward = 0;

void setup(){
pinMode(SW1_Forward, INPUT);
pinMode(SW2_Rigth, INPUT);
pinMode(SW3_Reward, INPUT);
pinMode(SW4_Left, INPUT);

pinMode(Relay_1A, OUTPUT);
pinMode(Relay_2A, OUTPUT);

pinMode(Relay_1B, OUTPUT);
pinMode(Relay_2B, OUTPUT);
Serial.begin(9600);
}

void loop(){

how to use void forward with my loop****** please help meee!!!

}

void forward(){
digitalWrite(Relay_1A, HIGH);
digitalWrite(Relay_2A, LOW);
digitalWrite(Relay_1B, HIGH);
digitalWrite(Relay_2B, LOW);

return;
}
void reward(){
digitalWrite(Relay_1A, LOW);
digitalWrite(Relay_2A, HIGH);
digitalWrite(Relay_1B, LOW);
digitalWrite(Relay_2B, HIGH);
return;
}
void left(){
digitalWrite(Relay_1A, LOW);
digitalWrite(Relay_2A, LOW);
digitalWrite(Relay_1B, HIGH);
digitalWrite(Relay_2B, LOW);
return;
}
void right(){
digitalWrite(Relay_1A, HIGH);
digitalWrite(Relay_2A, LOW);
digitalWrite(Relay_1B, LOW);
digitalWrite(Relay_2B, LOW);
return;
}

Why is there a reference to "table tennis balls" in your title?

If you want to call a function you do it like this

void loop() {
  forward();
}

and note that the proper name for it is "function" and not "void". The word "void" is there to tell the compiler that the function will not return a value.

...R

Robin2:
Why is there a reference to "table tennis balls" in your title?

If you want to call a function you do it like this

void loop() {

forward();
}




and note that the proper name for it is "function" and not "void". The word "void" is there to tell the compiler that the function will not return a value.

...R

thank you sir, but i have 4 SW for control my Relay 4 channel. can i write

void loop(){
if(digitalRead(SW1_Forward) == HIGH){
forward();
delay(100);
}
}

phatthawat:
thank you sir, but i have 4 SW for control my Relay 4 channel. can i write

Did you try it?

What happened?

For many Arduino questions you will get an answer much quicker, and probably learn more, by trying things out.

...R

PS. The answer to your question is "yes"

PPS. You did not answer my question about "table tennis balls"

Robin2:
Did you try it?

What happened?

For many Arduino questions you will get an answer much quicker, and probably learn more, by trying things out.

...R

PS. The answer to your question is "yes"

PPS. You did not answer my question about "table tennis balls"

sorry sir, i'm try it but continuous for working i want it stop when i press SW 1 time and relay work 1 time too.

I'm so sorry about "Table tennis balls" now edit to "i want to make robot car keep tennis balls" i want to make like this:

https://www.google.co.th/search?q=หุ่นยนต์เก็บลูกปิงปอง&source=lnms&tbm=isch&sa=X&ved=0ahUKEwjNkrn24uTVAhXLMI8KHUUMDQUQ_AUICigB&biw=1198&bih=825#imgrc=_wtDbGF7t05rUM:

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Have you got 10K resisitor connected between each of your digital input pins and gnd, so that the input goes LOW when you switch OFF with your button?


Tom... :slight_smile:

TomGeorge:
Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Have you got 10K resisitor connected between each of your digital input pins and gnd, so that the input goes LOW when you switch OFF with your button?


Tom... :slight_smile:

Thank you so much sir.

phatthawat:
Thank you so much sir.

Does that mean that everything is now working?

...R

Robin2:
Does that mean that everything is now working?

...R

yes, i write it to new code it working. thank you for your helping me.

Hi,

We have helped you with your project, its time to show your results for us to see.

Can you post your working code, so anyone having a similar problem/inquiry can see a solution.

Thanks.. Tom... :slight_smile: