GAMBAR DI ATAS MERAKIT SENSOR KIRI-KANAN
GAMBAR DI ATAS LAMBANG KOMPONEN HUBUNGAN ATAR RELAY
PROGRAM PENGECEKAN ROBOT
int x;
int y;
void setup (){
Serial.begin(9600);
pinMode(6,OUTPUT); //roda kiri
pinMode(7,OUTPUT); //roda kiri
pinMode(8,OUTPUT); //roda kanan
pinMode(9,OUTPUT); //roda kanan
pinMode(10,OUTPUT); //power mengantur kecepatan putaran roda
}
void mundur(){
analogWrite(10,255);
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
digitalWrite(8,HIGH);
digitalWrite(9,LOW);
}
void maju(){
analogWrite(10,255);
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
digitalWrite(8,LOW);
digitalWrite(9,HIGH);
}
void belokiri(){
analogWrite(10,120);
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,HIGH);
}
void luruskanan(){
analogWrite(10,110);
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
}
void belokanan(){
analogWrite(10,120);
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
digitalWrite(9,LOW);
}
void luruskiri(){
analogWrite(10,110);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,HIGH);
}
void diam (){
analogWrite(10,255);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
}
void loop (){
int y=analogRead(A0);
int x=analogRead(A1);
// Serial.print("SensorA0= ");
// Serial.print(y);
// Serial.print(" SensorA1= ");
// Serial.println(x);
// delay(500); */
if ( y<200 && x<200)
{maju();}
else if (y>200 && x>200)
{maju();}
else if (y <200 && x>200)
{belokanan();
luruskiri();}
else if (y>200 && x<200)
{belokiri();
luruskanan();}
}
Tidak ada komentar:
Posting Komentar