Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // include the library code:
- #include <LiquidCrystal.h> // use the library for Display
- #include <IRremote.h> // use the library for IR
- const int receiver = 10; // pin of IR receiver to Arduino
- const int bulb = 9; // To bulb or whatever you connect.
- // initialize the library with the numbers of the interface pins
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
- int fadeValue;
- int lastCounter = 1;
- int counter;
- #define code1 32895 // code received from button A
- #define code2 36975 // code received from button B
- IRrecv irrecv(receiver); // create instance of 'irrecv'
- decode_results results;
- void setup() {
- Serial.begin(9600); // you can comment this line
- //Set up the output pin
- pinMode(bulb, OUTPUT);
- //Ir
- irrecv.enableIRIn();
- // set up the LCD's number of columns and rows:
- lcd.begin(16, 2);
- }
- void loop() {
- lcd.setCursor(0, 0); // set cursor to top left & first colum
- lcd.print("Bulb Dimmer!");
- counter = lastCounter;
- if (irrecv.decode(&results))
- {
- unsigned int value = results.value;
- if (value == code1) {
- counter ++;
- lcd.clear();// clear lcd
- }
- if (value == code2) {
- counter --;
- lcd.clear(); // clear lcd
- }
- Serial.println("IR receive code"); Serial.println(value); // you can comment this line
- irrecv.resume();
- }
- if (counter > 5) { //maximum for counter = 5
- counter = 5;
- }
- if (counter < 2) { //minimum for counter = 1
- counter = 1;
- }
- switch (counter) { //depending on the counter the fadevalue is sent to the led
- case 1:
- fadeValue = 00;
- lcd.setCursor(0, 1); // set cursor to bottom left & second colum
- lcd.print("OFF PRES VOL+"); // LCD print
- break;
- case 2:
- fadeValue = 50;
- lcd.setCursor(0, 1); // set cursor to bottom left & second colum
- lcd.print("Speed 1"); // LCD print
- break;
- case 3:
- fadeValue = 120;
- lcd.setCursor(0, 1); // set cursor to bottom left & second colum
- lcd.print("Speed 2"); // LCD print
- break;
- case 4:
- fadeValue = 185;
- lcd.setCursor(0, 1); // set cursor to bottom left & second colum
- lcd.print("Speed 3"); // LCD print
- break;
- case 5:
- fadeValue = 255;
- lcd.setCursor(0, 1); // set cursor to bottom left & second colum
- lcd.print("MAX PRES VOL-"); // LCD print
- break;
- }
- analogWrite(bulb, fadeValue); //set led with PWM value
- lastCounter = counter; //reset counter
- }
Add Comment
Please, Sign In to add comment