//////// ARDUINO
///////code by V. SaiKiran.......https://www.facebook.com/saikiran27
#include <IRremote.h>
#include <Servo.h>
Servo front; // create servo object to control a servo
Servo center;
Servo rear;
Servo bass;
int LED=0; //power status initially set OFF
int pos1=10; // variable to store the servo position
int pos2=10;
int pos3=10;
int pos4=10;
int x=10; // increment or decrement angle of any servo
int RECV_PIN = 11; //out pin of tsop sensor
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
front.attach(10); // attaches the servo on pin 10 to the servo object
front.write(10);
center.attach(9);
center.write(10);
rear.attach(6);
rear.write(10);
bass.attach(5);
bass.write(10);
pinMode(13,OUTPUT);
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop()
{
if (irrecv.decode(&results))
{
Serial.println(results.value);
//POWER LOOP
if(results.value==284131455)
{
if(LED==0)
{
LED=1;
digitalWrite(13,HIGH);
}
else
if(LED==1)
{
LED=0;
digitalWrite(13,LOW);
}
}
//RESET LOOP
if(results.value==284119215)
{
pos1=30;
pos2=30;
pos3=30;
pos4=30;
front.write(pos1);
center.write(pos2);
rear.write(pos3);
bass.write(pos4);
delay(15);
}
//MUTE LOOP
if(results.value==284151855)
{
pos1=10;
pos2=10;
pos3=10;
pos4=10;
front.write(pos1);
center.write(pos2);
rear.write(pos3);
bass.write(pos4);
delay(15);
}
//FRONT LOOP
if (results.value==284157975)
{
pos1+=x;
Serial.println(pos1);
if(10<pos1<170)
{
front.write(pos1);
delay(15);
}
else
{
pos1-=x;
}
}
if (results.value==284104935)
{
pos1-=x;
Serial.println(pos1);
if(10<pos1<170)
{
front.write(pos1);
delay(15);
}
else
{
pos1+=x;
}
}
//CENTER LOOP
if (results.value==284141655)
{
pos2+=x;
Serial.println(pos2);
if(10<pos2<170)
{
center.write(pos2);
delay(15);
}
else
{
pos2-=x;
}
}
if (results.value==284109015)
{
pos2-=x;
Serial.println(pos2);
if(10<pos2<170)
{
center.write(pos2);
delay(15);
}
else
{
pos2+=x;
}
}
//REAR LOOP
if (results.value==284125335)
{
pos3+=x;
Serial.println(pos3);
if(10<pos3<170)
{
rear.write(pos3);
delay(15);
}
else
{
pos3-=x;
}
}
if (results.value==284106975)
{
pos3-=x;
Serial.println(pos3);
if(10<pos3<170)
{
rear.write(pos3);
delay(15);
}
else
{
pos3+=x;
}
}
//MASTER VOLUME LOOP
if(results.value==284102895)
{
pos1+=x;
pos2+=x;
pos3+=x;
pos4+=x;
if(10<pos1&&pos2&&pos3&&pos4<170)
{
front.write(pos1);
center.write(pos2);
rear.write(pos3);
bass.write(pos4);
delay(15);
}
else
{
pos1-=x;
pos2-=x;
pos3-=x;
pos4-=x;
}
}
if(results.value==284100855)
{
pos1-=x;
pos2-=x;
pos3-=x;
pos4-=x;
if(10<pos1&&pos2&&pos3&&pos4<170)
{
front.write(pos1);
center.write(pos2);
rear.write(pos3);
bass.write(pos4);
delay(15);
}
else
{
pos1+=x;
pos2+=x;
pos3+=x;
pos4+=x;
}
}
//BASS LOOP
if (results.value==284098815)
{
pos4+=x;
Serial.println(pos4);
if(10<pos4<170)
{
bass.write(pos4);
delay(15);
}
else
{
pos4-=x;
}
}
if (results.value==284113095)
{
pos4-=x;
Serial.println(pos4);
if(10<pos4<170)
{
bass.write(pos4);
delay(15);
}
else
{
pos4+=x;
}
}
irrecv.resume(); // Receive the next value
}
}
No comments:
Post a Comment