//#include <IRremote.h>
#include <IRremote.hpp>
int kumandaPin = 2;
int motorAcmaPini = 8;
int motorA1Pini = 9;
int motorB1Pini = 10;
int motorHizPini = 11;
int motorAkimOlcmePini = A0;
IRrecv kumanda(kumandaPin);
decode_results sonuclar;
short motorHizi = 50;
void setup()
{
kumanda.enableIRIn();
pinMode(motorAcmaPini, OUTPUT);
pinMode(motorA1Pini, OUTPUT);
pinMode(motorB1Pini, OUTPUT);
pinMode(motorHizPini, OUTPUT);
pinMode(motorAkimOlcmePini, INPUT);
Serial.begin(9600);
}
void loop()
{
while (kumanda.decode(&sonuclar))
{
Serial.print("Tuş kodu: ");
Serial.println(sonuclar.value, HEX);
kumanda.resume();
digitalWrite(motorAcmaPini, HIGH);
if(sonuclar.value == 0xFFA25D)
{
digitalWrite(motorA1Pini, LOW);
digitalWrite(motorB1Pini, HIGH);
}
if(sonuclar.value == 0xFF629D)
{
digitalWrite(motorA1Pini, HIGH);
digitalWrite(motorB1Pini, LOW);
}
if(sonuclar.value == 0xFFB04F)
{
digitalWrite(motorA1Pini, LOW);
digitalWrite(motorB1Pini, LOW);
digitalWrite(motorAcmaPini, LOW);
}
if(sonuclar.value == 0xFF18E7)
{
hiziArtir();
}
if(sonuclar.value == 0xFF4AB5)
{
hiziAzalt();
}
}
delay(100);
}
void hiziArtir()
{
motorHizi = motorHizi + 10;
if (motorHizi > 100)
{
motorHizi = 100;
}
Serial.print("Motor Speed: %");
Serial.println(motorHizi);
analogWrite(motorHizPini, round(motorHizi * 2.55));
}
void hiziAzalt()
{
motorHizi = motorHizi - 10;
if (motorHizi < 0)
{
motorHizi = 0;
}
Serial.print("Motor Speed: %");
Serial.println(motorHizi);
analogWrite(motorHizPini, round(motorHizi* 2.55));
}
void motoraGonder (short hedefYon, short hedefHiz)
{
analogWrite(motorHizPini, round(hedefHiz * 2.55));
}