const int AIA = 9; // (pwm) pin 9 connected to pin A-IA const int AIB = 5; // (pwm) pin 5 connected to pin A-IB const int BIA = 10; // (pwm) pin 10 connected to pin B-IA const int BIB = 6; // (pwm) pin 6 connected to pin B-IB int lampudepan = 11; int lampubelakang = 12; int horn = 4; byte speed = 255; // change this (0-255) to control the speed of the motors char command; void setup() { Serial.begin(9600); pinMode(AIA, OUTPUT); // set pins to output pinMode(AIB, OUTPUT); pinMode(BIA, OUTPUT); pinMode(BIB, OUTPUT); pinMode(lampudepan, OUTPUT); pinMode(lampubelakang, OUTPUT); pinMode(horn, OUTPUT); }
void loop() { if(Serial.available() > 0){ command = Serial.read(); Stop(); //initialize with motors stoped //Change pin mode only if new command is different from previous. //Serial.println(command); switch(command){ case 'F': Forward(); break; case 'B': Back(); break; case 'L': Left(); break; case 'R': Right(); break; } } if(command=='W'){ digitalWrite(lampudepan,HIGH); } if (command=='w'){ digitalWrite(lampudepan,LOW); } if(command=='U'){ digitalWrite(lampubelakang,HIGH); } if (command=='u'){ digitalWrite(lampubelakang,LOW); } if(command=='V'){ digitalWrite(horn,HIGH); } if (command=='v'){ digitalWrite(horn,LOW); } }
where are the codes of this project.....
BalasHapusconst int AIA = 9; // (pwm) pin 9 connected to pin A-IA
Hapusconst int AIB = 5; // (pwm) pin 5 connected to pin A-IB
const int BIA = 10; // (pwm) pin 10 connected to pin B-IA
const int BIB = 6; // (pwm) pin 6 connected to pin B-IB
int lampudepan = 11;
int lampubelakang = 12;
int horn = 4;
byte speed = 255; // change this (0-255) to control the speed of the motors
char command;
void setup() {
Serial.begin(9600);
pinMode(AIA, OUTPUT); // set pins to output
pinMode(AIB, OUTPUT);
pinMode(BIA, OUTPUT);
pinMode(BIB, OUTPUT);
pinMode(lampudepan, OUTPUT);
pinMode(lampubelakang, OUTPUT);
pinMode(horn, OUTPUT);
}
void loop() {
if(Serial.available() > 0){
command = Serial.read();
Stop(); //initialize with motors stoped
//Change pin mode only if new command is different from previous.
//Serial.println(command);
switch(command){
case 'F':
Forward();
break;
case 'B':
Back();
break;
case 'L':
Left();
break;
case 'R':
Right();
break;
}
}
if(command=='W'){
digitalWrite(lampudepan,HIGH);
}
if (command=='w'){
digitalWrite(lampudepan,LOW);
}
if(command=='U'){
digitalWrite(lampubelakang,HIGH);
}
if (command=='u'){
digitalWrite(lampubelakang,LOW);
}
if(command=='V'){
digitalWrite(horn,HIGH);
}
if (command=='v'){
digitalWrite(horn,LOW);
}
}
void Forward()
{
analogWrite(AIA, 0);
analogWrite(AIB, speed);
analogWrite(BIA, 0);
analogWrite(BIB, speed);
}
void Back()
{
analogWrite(AIA, speed);
analogWrite(AIB, 0);
analogWrite(BIA, speed);
analogWrite(BIB, 0);
}
void Left()
{
analogWrite(AIA, speed);
analogWrite(AIB, 0);
analogWrite(BIA, 0);
analogWrite(BIB, 0);
}
void Right()
{
analogWrite(AIA, 0);
analogWrite(AIB, 0);
analogWrite(BIA, speed);
analogWrite(BIB, 0);
}
void Stop()
{
analogWrite(AIA, 0);
analogWrite(AIB, 0);
analogWrite(BIA, 0);
analogWrite(BIB, 0);
}