Mini Sumo Robot Yazılımı Arduino

  • Koronavirüs ile mücadelede sende devlete yardımcı ol #evdekal. Unutma #evdehayatvar.

aydogan

Bilgili Üye
ÜSTÜN
18 Eki 2019
17
20
13
#1
//Bileyim.com yazılım ekibi
#define sag_sensor A5
#define sol_sensor 1
#define orta_sensor 0

#define sag_cizgi 7
#define orta_cizgi 6
#define sol_cizgi 5

#define sol_motor1 A4
#define sol_motor2 A3
#define sol_pwm 9

#define sag_motor1 A1
#define sag_motor2 A2
#define sag_pwm 10

#define D3 11 //led1
#define D2 12 //led2
#define D1 13 //led3
#define buzzer 8
#define buton A0

bool sag, sol = 0;
bool sag_yon1 = 0, sag_yon2 = 0, sol_yon1 = 0, sol_yon2 = 0;

int sag_artis = 120, sol_artis = 120;

void setup() {
pinMode(sag_sensor, INPUT);
pinMode(orta_sensor, INPUT);
pinMode(sol_sensor, INPUT);

pinMode(sag_cizgi, INPUT);
pinMode(orta_cizgi, INPUT);
pinMode(sol_cizgi, INPUT);

pinMode(sol_motor1, OUTPUT);
pinMode(sol_motor2, OUTPUT);
pinMode(sol_pwm, OUTPUT);

pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);

pinMode(sag_motor1, OUTPUT);
pinMode(sag_motor2, OUTPUT);
pinMode(sag_pwm, OUTPUT);

pinMode(buton, INPUT);
pinMode(buzzer, OUTPUT);

digitalWrite(buton, HIGH);
}

void loop() {

{
////////MÝNÝ SUMO (FROG)//////////
for (int i = 0; i < 2; i++) {
digitalWrite(D2, HIGH);
noTone(buzzer);
delay(200);
tone(buzzer, 800);
delay(300);
noTone(buzzer);
delay(200);
}
digitalWrite(D2, HIGH);
minisumo :

if (digitalRead(buton) == 1)
{
for (int i = 0; i < 5; i++) {
noTone(buzzer);
delay(200);
tone(buzzer, 800);
delay(500);
noTone(buzzer);
delay(300);
}
while (1)
{
if (digitalRead(sag_cizgi) == 0)
{
digitalWrite(sol_motor1, LOW);
digitalWrite(sol_motor2, HIGH);
analogWrite(sol_pwm, 255);

digitalWrite(sag_motor1, LOW);
digitalWrite(sag_motor2, HIGH);
analogWrite(sag_pwm, 255);
delay(300);

digitalWrite(sol_motor1, LOW);
digitalWrite(sol_motor2, HIGH);
analogWrite(sol_pwm, 255);

digitalWrite(sag_motor1, HIGH);
digitalWrite(sag_motor2, LOW);
analogWrite(sag_pwm, 255);
delay(300);
}
else if (digitalRead(sol_cizgi) == 0)
{
digitalWrite(sol_motor1, LOW);
digitalWrite(sol_motor2, HIGH);
analogWrite(sol_pwm, 255);

digitalWrite(sag_motor1, LOW);
digitalWrite(sag_motor2, HIGH);
analogWrite(sag_pwm, 255);
delay(300);

digitalWrite(sol_motor1, LOW);
digitalWrite(sol_motor2, HIGH);
analogWrite(sol_pwm, 255);

digitalWrite(sag_motor1, HIGH);
digitalWrite(sag_motor2, LOW);
analogWrite(sag_pwm, 255);
delay(300);
}
else if (digitalRead(sag_sensor) == 0)
{
digitalWrite(sol_motor1, LOW);
digitalWrite(sol_motor2, HIGH);
analogWrite(sol_pwm, 255);

digitalWrite(sag_motor1, HIGH);
digitalWrite(sag_motor2, LOW);
analogWrite(sag_pwm, 255);
sag = 1;
sol = 0;
}
else if (digitalRead(sol_sensor) == 0)
{
digitalWrite(sol_motor1, HIGH);
digitalWrite(sol_motor2, LOW);
analogWrite(sol_pwm, 255);

digitalWrite(sag_motor1, LOW);
digitalWrite(sag_motor2, HIGH);
analogWrite(sag_pwm, 255);
sag = 0;
sol = 1;
}
else if (digitalRead(orta_sensor) == 0)
{
digitalWrite(sol_motor1, HIGH);
digitalWrite(sol_motor2, LOW);
analogWrite(sol_pwm, 255);

digitalWrite(sag_motor1, HIGH);
digitalWrite(sag_motor2, LOW);
analogWrite(sag_pwm, 255);
}
else
{
if (sag == 1)
{
digitalWrite(sol_motor1, LOW);
digitalWrite(sol_motor2, HIGH);
analogWrite(sol_pwm, 255);

digitalWrite(sag_motor1, HIGH);
digitalWrite(sag_motor2, LOW);
analogWrite(sag_pwm, 255);
}
else if (sol == 1)
{
digitalWrite(sol_motor1, HIGH);
digitalWrite(sol_motor2, LOW);
analogWrite(sol_pwm, 255);

digitalWrite(sag_motor1, LOW);
digitalWrite(sag_motor2, HIGH);
analogWrite(sag_pwm, 255);
}
else if (sag == 0 && sol == 0)
{
digitalWrite(sol_motor1, HIGH);
digitalWrite(sol_motor2, LOW);
analogWrite(sol_pwm, 255);

digitalWrite(sag_motor1, HIGH);
digitalWrite(sag_motor2, LOW);
analogWrite(sag_pwm, 255);
}
}
}
}
}
}




Devre şeması yazılımın en başında açık bir şekilde anlatılıyor :)