#include <IRremote.h>
#include <IRremoteInt.h>
#include <Servo.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // LCD screen setup RS,E,D4,D5,D6,D7
int RECV_PIN=8; //IR pin
IRrecv irrecv(RECV_PIN);
decode_results results ;
Servo myservo;
int angle = 0; //setup angle
void setup()
{
lcd.begin(16, 2); //LCD 16*2
myservo.attach(9); //Servo pin
myservo.write(angle); //write servo value=0
irrecv.enableIRIn(); // enable IR
lcd.setCursor(0, 0); //this is a loading bar, not a nice code...but work:)
lcd.print("Betoltes..."); //print the text
delay(800);
lcd.clear();
lcd.print("Betoltes>");
delay(400);
lcd.clear();
lcd.print("Betoltes>>");
delay(400);
lcd.clear();
lcd.print("Betoltes>>>");
delay(400);
lcd.clear();
lcd.print("Betoltes>>>>");
delay(400);
lcd.clear();
lcd.print("Betoltes>>>>>");
delay(400);
lcd.clear();
lcd.print("Betoltes>>>>>>");
delay(400);
lcd.clear();
lcd.print("Betoltes>>>>>>>");
delay(400);
lcd.clear();
lcd.print("Motor szoge:"); //print the text
lcd.setCursor(0, 1); //set cursor 2. line
lcd.print(angle); //print the servo value
}
void loop()
{
if(irrecv.decode(&results)) //read ir code
{
translateIR();
myservo.write(angle);
if (angle>180) //when servo angle value max print maximum text
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Motor szoge:");
lcd.setCursor(0, 1);
lcd.print("Maximum szog");
angle = 190;
}
else if (angle<0) //when servo angle value min print minimum text
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Motor szoge:");
lcd.setCursor(0, 1);
lcd.print("Minimum szog");
angle = -10;
}
else //print servo angle value
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Motor szoge:");
lcd.setCursor(0, 1);
lcd.print(angle);
}
irrecv.resume();
}
}
void translateIR() //
{
switch(results.value) {
case 0xFF6897: //0 button
angle = 0; //set angle minimum value
break;
case 0xFF30CF: //1 button
angle = angle + 10; //increase angle value
break;
case 0xFF18E7: //2 button
angle = angle -10; //decrease angle value
break;
case 0xFF7A85: //3 button
angle = 180; //set angle maximum value
break;
}
}
Comments