// Vienspalvio led
// efektų
#include <IRremote.h>
#include <LiquidCrystal.h>
#define PIN_RECEIVER 2 // Signal Pin of IR receiver
IRrecv receiver(PIN_RECEIVER);
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
#define LDR_PIN 2
int ledPin = 9; // pin for the LED
// LDR Characteristics
const float GAMMA = 0.7;
const float RL10 = 50;
#define redPin 6
#define greenPin 5
#define bluePin 3
void setup()
{
// pinMode(ledPin, OUTPUT);
pinMode(LDR_PIN, INPUT);
lcd.begin(16, 2);
lcd.print("<press a button>");
receiver.enableIRIn(); // Start the receiver
}
void loop()
{
setRGB(0, 255, 255);
int brightness = map(luxValue(), 0, 1023, 0, 255);
// analogWrite(ledPin, brightness);
// Checks received an IR signal
if (receiver.decode()) {
translateIR();
receiver.resume(); // Receive the next value
}
}
void automaticLight() {
// get the current hour
int hour = getHour();
// set the color of the LED based on the hour
if (hour >= 6 && hour < 12) {
// warm white during the morning
setRGB(255, 245, 225);
lcd.setCursor(0, 1);
lcd.print("Morning");
} else if (hour >= 12 && hour < 18) {
// neutral white during the afternoon
setRGB(255, 255, 255);
lcd.setCursor(0, 1);
lcd.print("Afternoon");
} else if (hour >= 18 && hour < 22) {
// warm white during the evening
setRGB(255, 245, 225);
lcd.setCursor(0, 1);
lcd.print("Evening");
} else {
// cool white during the night
setRGB(200, 220, 255);
lcd.setCursor(0, 1);
lcd.print("Night");
}
};
int getHour() {
return 12;
};
float luxValue() {
// check light sensor
int analogValue = analogRead(A0);
float voltage = analogValue / 1024. * 5;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
return lux;
}
void lcdPrint(char* text)
{
float luxvalue1 = luxValue();
lcd.clear();
lcd.setCursor(0, 0);
if(text == "TEST"){
lcd.setCursor(2, 0);
lcd.print("Room: ");
if (luxvalue1> 50) {
lcd.print("Light!");
} else {
lcd.print("Dark ");
}
lcd.setCursor(0, 1);
lcd.print("Lux: ");
lcd.print(luxvalue1);
lcd.print(" ");
delay(100);
}
else if(text == "MENU"){
automaticLight();
}
else if(text == "PLAY"){
setRGB(1, 244, 5);
}
else if(text == "num: 1"){
setBlinking(244, 244, 244);
}
else if(text == "PLUS"){
if()
setRGB(1, 0, 0);
// colorRGB(255, 0, 0); //Brightness level 255
// colorRGB(150, 0, 0); //Brightness level 150
// colorRGB(50, 0, 0); //Brightness level 50
}
else if(text == "MINUS"){
setRGB(1, 0, 0);
}
else {
lcd.print("button pressed:");
lcd.setCursor(0, 1);
lcd.print(text);
lcd.print(" code: ");
lcd.print(receiver.decodedIRData.command);
}
}
void setRGB(int r, int g, int b) {
// set the values for the red, green, and blue LED pins
analogWrite(redPin, r);
analogWrite(greenPin, g);
analogWrite(bluePin, b);
}
void setBlinking(int r, int g, int b) {
int Count = 0;
// set the values for the red, green, and blue LED pins
while (Count <= 10)
{
analogWrite(redPin, r);
analogWrite(greenPin, g);
analogWrite(bluePin, b);
delay(1000);
analogWrite(redPin, 0);
analogWrite(greenPin, 0);
analogWrite(bluePin, 0);
delay(1000);
Count++;
}
}
void translateIR()
{
// Takes command based on IR code received
switch (receiver.decodedIRData.command) {
case 162:
lcdPrint("POWER");
break;
case 226:
lcdPrint("MENU");
break;
case 34:
lcdPrint("TEST");
break;
case 2:
lcdPrint("PLUS");
break;
case 194:
lcdPrint("BACK");
break;
case 224:
lcdPrint("PREV.");
break;
case 168:
lcdPrint("PLAY");
break;
case 144:
lcdPrint("NEXT");
break;
case 104:
lcdPrint("num: 0");
break;
case 152:
lcdPrint("MINUS");
break;
case 176:
lcdPrint("key: C");
break;
case 48:
lcdPrint("num: 1");
break;
case 24:
lcdPrint("num: 2");
break;
case 122:
lcdPrint("num: 3");
break;
case 16:
lcdPrint("num: 4");
break;
case 56:
lcdPrint("num: 5");
break;
case 90:
lcdPrint("num: 6");
break;
case 66:
lcdPrint("num: 7");
break;
case 74:
lcdPrint("num: 8");
break;
case 82:
lcdPrint("num: 9");
break;
default:
lcd.clear();
lcd.print(receiver.decodedIRData.command);
lcd.print(" other button");
}
}