// Bluetooth araç kontrolü- v2
// -------------------------------------------------------------
int hiz = 200; // robot hızı ayarlandı
//--------------------------------------------------------------
// motor sürücüsü pinleri belirlendi
const int sagenable = 10;
const int sagileri = 9;
const int saggeri = 8;
const int solileri = 7;
const int solgeri = 6;
const int solenable = 5;
const int buzzerPin = 4; // buzzer 4. pine bağlı
const int onlamba = 3; // ön lamba 3. pine bağlı
const int arkalamba = 2; // arka lamba 2. pine bağlı
const int eklamba = 11; // dikkat lambası 11. pine bağlı
//---------------------------------------------------------------
void setup(){
Serial.begin(9600);
pinMode(sagileri,OUTPUT);
pinMode(saggeri,OUTPUT);
pinMode(solileri,OUTPUT);
pinMode(solgeri,OUTPUT);
pinMode(sagenable,OUTPUT);
pinMode(solenable,OUTPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(onlamba, OUTPUT);
pinMode(arkalamba, OUTPUT);
pinMode(eklamba, OUTPUT);
}
//-----------------------------------------------------------------
void loop()
{
if (Serial.available() > 0) { // Bluetooth’tan veri geldi mi?
char tus = (char)Serial.read();
// -----------------------------
if( tus == 'F' )
ileri(hiz);
if( tus == 'B' )
geri(hiz);
if( tus == 'S' )
dur();
if( tus == 'L' )
solaDon(hiz);
if( tus == 'R' )
sagaDon(hiz);
// -----------------------------
if( tus == 'G' )
ileriSolaDon();
if( tus == 'I' )
ileriSagaDon();
if( tus == 'H' )
geriSolaDon();
if( tus == 'J' )
geriSagaDon();
// -----------------------------
if( tus == 'V' )
buzzerCalistir();
if( tus == 'v' )
buzzerDur();
// ------------------------------
if( tus == 'W' )
digitalWrite(onlamba,HIGH);
if( tus == 'w' )
digitalWrite(onlamba,LOW);
// ------------------------------
if( tus == 'U' )
digitalWrite(arkalamba,HIGH);
if( tus == 'u' )
digitalWrite(arkalamba,LOW);
// ------------------------------
if( tus == 'X' )
digitalWrite(eklamba,HIGH);
if( tus == 'x' )
digitalWrite(eklamba,LOW);
// ------------------------------
if( tus == '0' )
hiz=0;
if( tus == '1' )
hiz=25;
if( tus == '2' )
hiz=50;
if( tus == '3' )
hiz=75;
if( tus == '4' )
hiz=100;
if( tus == '5' )
hiz=125;
if( tus == '6' )
hiz=150;
if( tus == '7' )
hiz=175;
if( tus == '8' )
hiz=200;
if( tus == '9' )
hiz=225;
if( tus == 'q' )
hiz=255;
//---------------------------------
}
}
//---------------------------------------------------------------
void ileri(int hiz)
{
analogWrite(sagenable, hiz); // sağ motora hız verisi yüklendi
analogWrite(solenable, hiz); // sol motora hız verisi yüklendi
digitalWrite(sagileri, HIGH);
digitalWrite(solileri, HIGH);
digitalWrite(saggeri, LOW);
digitalWrite(solgeri, LOW);
}
void sagaDon(int hiz)
{
analogWrite(sagenable, 0);
analogWrite(solenable, hiz);
digitalWrite(sagileri,LOW);
digitalWrite(saggeri,HIGH);
digitalWrite(solileri, HIGH);
digitalWrite(solgeri,LOW);
}
void solaDon(int hiz)
{
analogWrite(sagenable, hiz);
analogWrite(solenable, 0);
digitalWrite(sagileri,HIGH);
digitalWrite(saggeri,LOW);
digitalWrite(solileri, LOW);
digitalWrite(solgeri,HIGH);
}
void geri(int hiz)
{
analogWrite(sagenable, hiz);
analogWrite(solenable, hiz);
digitalWrite(sagileri,LOW);
digitalWrite(saggeri, HIGH);
digitalWrite(solileri, LOW);
digitalWrite(solgeri, HIGH);
}
void dur()
{
digitalWrite(sagileri, HIGH);
digitalWrite(saggeri, HIGH);
digitalWrite(solileri, HIGH);
digitalWrite(solgeri, HIGH);
}
void ileriSagaDon()
{
analogWrite(sagenable, 50); // sağ motora hız verisi yüklendi
analogWrite(solenable, 110); // sol motora hız verisi yüklendi
digitalWrite(sagileri, HIGH);
digitalWrite(solileri, HIGH);
digitalWrite(saggeri, LOW);
digitalWrite(solgeri, LOW);
}
void ileriSolaDon()
{
analogWrite(sagenable, 110); // sağ motora hız verisi yüklendi
analogWrite(solenable, 50); // sol motora hız verisi yüklendi
digitalWrite(sagileri, HIGH);
digitalWrite(solileri, HIGH);
digitalWrite(saggeri, LOW);
digitalWrite(solgeri, LOW);
}
void geriSagaDon()
{
analogWrite(sagenable, 50);
analogWrite(solenable, 110);
digitalWrite(sagileri,LOW);
digitalWrite(saggeri, HIGH);
digitalWrite(solileri, LOW);
digitalWrite(solgeri, HIGH);
}
void geriSolaDon()
{
analogWrite(sagenable, 110);
analogWrite(solenable, 50);
digitalWrite(sagileri,LOW);
digitalWrite(saggeri, HIGH);
digitalWrite(solileri, LOW);
digitalWrite(solgeri, HIGH);
}
void buzzerCalistir()
{
digitalWrite(buzzerPin, HIGH);
}
void buzzerDur()
{
digitalWrite(buzzerPin, LOW);
}
void hizlan()
{
for(int hiz_degeri = 0 ; hiz_degeri <= 255; hiz_degeri +=5)
{
analogWrite(sagenable, hiz_degeri);
analogWrite(solenable, hiz_degeri);
delay(30);
}
}
void yavasla()
{
for(int hiz_degeri = 255 ; hiz_degeri >= 0; hiz_degeri -=5)
{
analogWrite(sagenable, hiz_degeri);
analogWrite(solenable, hiz_degeri);
delay(30);
}
}
Hiç yorum yok:
Yorum Gönder