Guest User

Untitled

a guest
May 23rd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. // include the library code:
  2. #include <LiquidCrystal.h> // use the library for Display
  3. #include <IRremote.h> // use the library for IR
  4.  
  5. const int receiver = 10; // pin of IR receiver to Arduino
  6. const int bulb = 9; // To bulb or whatever you connect.
  7. // initialize the library with the numbers of the interface pins
  8. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  9.  
  10. int fadeValue;
  11. int lastCounter = 1;
  12. int counter;
  13.  
  14. #define code1 32895 // code received from button A
  15. #define code2 36975 // code received from button B
  16.  
  17. IRrecv irrecv(receiver); // create instance of 'irrecv'
  18. decode_results results;
  19.  
  20.  
  21. void setup() {
  22. Serial.begin(9600); // you can comment this line
  23. //Set up the output pin
  24. pinMode(bulb, OUTPUT);
  25. //Ir
  26. irrecv.enableIRIn();
  27. // set up the LCD's number of columns and rows:
  28. lcd.begin(16, 2);
  29. }
  30.  
  31. void loop() {
  32. lcd.setCursor(0, 0); // set cursor to top left & first colum
  33. lcd.print("Bulb Dimmer!");
  34.  
  35. counter = lastCounter;
  36. if (irrecv.decode(&results))
  37. {
  38. unsigned int value = results.value;
  39. if (value == code1) {
  40. counter ++;
  41. lcd.clear();// clear lcd
  42. }
  43. if (value == code2) {
  44. counter --;
  45. lcd.clear(); // clear lcd
  46. }
  47.  
  48. Serial.println("IR receive code"); Serial.println(value); // you can comment this line
  49. irrecv.resume();
  50. }
  51.  
  52. if (counter > 5) { //maximum for counter = 5
  53. counter = 5;
  54.  
  55. }
  56.  
  57. if (counter < 2) { //minimum for counter = 1
  58. counter = 1;
  59. }
  60.  
  61. switch (counter) { //depending on the counter the fadevalue is sent to the led
  62.  
  63. case 1:
  64. fadeValue = 00;
  65. lcd.setCursor(0, 1); // set cursor to bottom left & second colum
  66. lcd.print("OFF PRES VOL+"); // LCD print
  67. break;
  68.  
  69. case 2:
  70. fadeValue = 50;
  71. lcd.setCursor(0, 1); // set cursor to bottom left & second colum
  72. lcd.print("Speed 1"); // LCD print
  73. break;
  74.  
  75. case 3:
  76. fadeValue = 120;
  77. lcd.setCursor(0, 1); // set cursor to bottom left & second colum
  78. lcd.print("Speed 2"); // LCD print
  79. break;
  80.  
  81. case 4:
  82. fadeValue = 185;
  83. lcd.setCursor(0, 1); // set cursor to bottom left & second colum
  84. lcd.print("Speed 3"); // LCD print
  85. break;
  86.  
  87. case 5:
  88. fadeValue = 255;
  89. lcd.setCursor(0, 1); // set cursor to bottom left & second colum
  90. lcd.print("MAX PRES VOL-"); // LCD print
  91. break;
  92.  
  93. }
  94.  
  95. analogWrite(bulb, fadeValue); //set led with PWM value
  96. lastCounter = counter; //reset counter
  97.  
  98. }
Add Comment
Please, Sign In to add comment