//Servo motor, IR sensor and IR rays
#include <IRremote.h>
#include <Servo.h>
#include <FastLED.h>
CRGB leds[0];
int pin_receiver = 2;
int button_value = 0;
int bright = 20;
Servo myservo1;
IRrecv receiver(pin_receiver);
void setup()
{
receiver.enableIRIn(); // enabling the IR receiver functionality
myservo1.attach(10);
Serial.begin(9600);
FastLED.addLeds<NEOPIXEL, 3>(leds, 1); // 3 is the pin terminal of arduino
// 1st LED should work from all connected Leds
}
void loop()
{
if (receiver.decode())
{
translateIR();
receiver.resume();
}
}
void translateIR()
{
button_value = receiver.decodedIRData.command; // button_value is the unique code of IR Remote buttons
if(button_value == 226) // Menu
{
Serial.println("Forward - Driver Door opens, Backward - Driver Door Close,");
Serial.println("1 - Lights ON in RED, 2 - Lights ON in Green,");
Serial.println("3 - LIGHTS ON in Blue Color, 4 - Blinking LED,");
Serial.println("Play - Control LED Glow, 9 - All stops");
}
if(button_value == 224) // Previous button
{
myservo1.write(0); // write method which sets the action to be performed
// by the connected Servo motor.
Serial.println("Door Closed");
}
if(button_value == 144)// Next Button
{
myservo1.write(180);
Serial.println("Door Open");
}
if(button_value == 48) // button 1
{
leds[1] = CRGB::Red; // CRGB defines the color as RGB format
FastLED.show();
}
if(button_value == 24) // button 2
{
leds[1] = CRGB::Green;
FastLED.show();
}
if(button_value == 122) // button 3
{
leds[1] = CRGB::Blue;
FastLED.show();
}
if(button_value == 16) // button 4
{
for (int i = 0; i<=20; i++)
{
leds[1] = CRGB(0, 255, 221);
FastLED.show();
delay(50);
leds[1] = CRGB(233, 255, 34);
FastLED.show();
delay(50);
leds[1] = CRGB(255, 0, 191);
FastLED.show();
delay(50);
}
}
if (button_value == 168) // Play button
{
bright = bright + 40; // increment the “bright” variable by 40.
FastLED.setBrightness(bright); //function of FastLED to set the brightness of NeoPixel LED
FastLED.show(); // displaying the defined Brightness on NeoPixel LED
}
if(button_value == 162) // Power button
{
Serial.println("Application Stopped");
myservo1.write(90); // write method which sets the action to be performed
// by the connected Servo motor.
// 90 is the rotation degree
FastLED.clear();
FastLED.show();
}
}