Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update rc_keyboard_control.ino #257

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 110 additions & 52 deletions arduino/rc_keyboard_control.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,100 +3,158 @@ int right_pin = 6;
int left_pin = 7;
int forward_pin = 10;
int reverse_pin = 9;
/int f1 = A2;
int re1 = A3;
int l1 = A4;
int r1 = A5;/

// duration for output
int time = 50;
// initial command
int command = 0;

void setup() {
pinMode(right_pin, OUTPUT);
pinMode(left_pin, OUTPUT);
pinMode(forward_pin, OUTPUT);
pinMode(reverse_pin, OUTPUT);
Serial.begin(115200);
pinMode(right_pin, OUTPUT);
pinMode(left_pin, OUTPUT);
pinMode(forward_pin, OUTPUT);
pinMode(reverse_pin, OUTPUT);
/* pinMode(f1, OUTPUT);
pinMode(re1, OUTPUT);
pinMode(l1, OUTPUT);
pinMode(r1, OUTPUT);*/
digitalWrite(forward_pin, LOW);
digitalWrite(reverse_pin, LOW);
digitalWrite(right_pin, LOW);
digitalWrite(left_pin, LOW);
digitalWrite(f1, LOW);
digitalWrite(re1, LOW);
digitalWrite(r1, LOW);
digitalWrite(l1, LOW);/
Serial.begin(115200);
}

void loop() {
//receive command
if (Serial.available() > 0){
command = Serial.read();
}
else{
reset();
}
send_command(command,time);
//receive command
if (Serial.available() > 0){
command = Serial.read();
}
else{
reset();
}
send_command(command,time);
}

void right(int time){
digitalWrite(right_pin, LOW);
delay(time);
digitalWrite(right_pin, HIGH);
//digitalWrite(r1, HIGH);
delay(time);
// digitalWrite(right_pin, LOW);
//digitalWrite(r1, LOW);

}

void left(int time){
digitalWrite(left_pin, LOW);
delay(time);
digitalWrite(left_pin, HIGH);
// digitalWrite(l1, HIGH);
delay(time);
// digitalWrite(left_pin, LOW);
//digitalWrite(l1, LOW);
}

void forward(int time){
digitalWrite(forward_pin, LOW);
delay(time);
digitalWrite(forward_pin, HIGH);
//digitalWrite(f1, HIGH);
delay(time);
//digitalWrite(forward_pin, LOW);
//digitalWrite(f1, LOW);
}

void reverse(int time){
digitalWrite(reverse_pin, LOW);
delay(time);
digitalWrite(reverse_pin, HIGH);
//digitalWrite(re1, HIGH);
delay(time);
//digitalWrite(reverse_pin, LOW);
//digitalWrite(re1, LOW);
}

void forward_right(int time){
digitalWrite(forward_pin, LOW);
digitalWrite(right_pin, LOW);
delay(time);
digitalWrite(forward_pin, HIGH);
//digitalWrite(f1, HIGH);
digitalWrite(right_pin, HIGH);
//digitalWrite(r1, HIGH);
delay(time);
// digitalWrite(forward_pin, LOW);
//digitalWrite(f1, LOW);
//digitalWrite(right_pin, LOW);
//digitalWrite(r1, LOW);
}

void reverse_right(int time){
digitalWrite(reverse_pin, LOW);
digitalWrite(right_pin, LOW);
delay(time);
digitalWrite(reverse_pin, HIGH);
//digitalWrite(re1, HIGH);
digitalWrite(right_pin, HIGH);
//digitalWrite(l1, HIGH);
delay(time);
//digitalWrite(reverse_pin, LOW);
//digitalWrite(re1, LOW);
//digitalWrite(right_pin, LOW);
//digitalWrite(l1, LOW);

}

void forward_left(int time){
digitalWrite(forward_pin, LOW);
digitalWrite(left_pin, LOW);
delay(time);
digitalWrite(forward_pin, HIGH);
//digitalWrite(f1, HIGH);
digitalWrite(left_pin, HIGH);
// digitalWrite(l1, HIGH);
delay(time);
//digitalWrite(forward_pin, LOW);
//digitalWrite(f1, LOW);
//digitalWrite(left_pin, LOW);
//digitalWrite(l1, LOW);
}

void reverse_left(int time){
digitalWrite(reverse_pin, LOW);
digitalWrite(left_pin, LOW);
delay(time);
digitalWrite(reverse_pin, HIGH);
//digitalWrite(re1, HIGH);
digitalWrite(left_pin, HIGH);
//digitalWrite(l1, HIGH);
delay(time);
//digitalWrite(reverse_pin, LOW);
//digitalWrite(re1, LOW);
//digitalWrite(left_pin, LOW);
//digitalWrite(l1, LOW);
}

void reset(){
digitalWrite(right_pin, HIGH);
digitalWrite(left_pin, HIGH);
digitalWrite(forward_pin, HIGH);
digitalWrite(reverse_pin, HIGH);
digitalWrite(right_pin, LOW);
digitalWrite(left_pin, LOW);
digitalWrite(forward_pin, LOW);
digitalWrite(reverse_pin, LOW);
/digitalWrite(l1, LOW);
digitalWrite(r1, LOW);
digitalWrite(re1, LOW);
digitalWrite(f1, LOW);/
}

void send_command(int command, int time){
switch (command){
switch (command){

//reset command
case 0: reset(); break;
//reset command
case 0: reset(); break;

// single command
case 1: forward(time); break;
case 2: reverse(time); break;
case 3: right(time); break;
case 4: left(time); break;
// single command
case 1: forward(time); break;
case 2: reverse(time); break;
case 3: right(time); break;
case 4: left(time); break;

//combination command
case 6: forward_right(time); break;
case 7: forward_left(time); break;
case 8: reverse_right(time); break;
case 9: reverse_left(time); break;
//combination command
case 6: forward_right(time); break;
case 7: forward_left(time); break;
case 8: reverse_right(time); break;
case 9: reverse_left(time); break;

default: Serial.print("Inalid Command\n");
}
default: Serial.print("Inalid Command\n");
}
}