Advertisement
ChaOSzz

LCS_RGB_POT.ino

Feb 20th, 2022
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. #include <LiquidCrystal_I2C.h>
  2. LiquidCrystal_I2C lcd(0x27,16,2);
  3. int row = 0;
  4. #define Pot1 A0
  5. #define Pot2 A1
  6. #define Pot3 A2
  7. int Pot_1_blue = 0;
  8. int Pot_2_green = 0;
  9. int Pot_3_red = 0;
  10.  
  11. void setup() {
  12. pinMode(A0, INPUT);
  13. pinMode(A1, INPUT);
  14. pinMode(A2, INPUT);
  15. pinMode(3, OUTPUT);
  16. pinMode(6, OUTPUT);
  17. pinMode(5, OUTPUT);
  18. Serial.begin(9600);
  19. // put your setup code here, to run once:
  20. lcd.init();
  21. lcd.backlight();
  22. lcd.cursor();
  23. }
  24.  
  25. void loop() {
  26. Pot_1_blue = map(analogRead(Pot1),0,1024,0,255);
  27. Pot_2_green = map(analogRead(Pot2),0,1024,0,255);
  28. Pot_3_red = map(analogRead(Pot3),0,1024,0,255);
  29.  
  30. analogWrite(3,Pot_1_blue);
  31. analogWrite(5,Pot_2_green);
  32. analogWrite(6,Pot_3_red);
  33.  
  34. // put your main code here, to run repeatedly:
  35. lcd.setCursor(6,0);
  36. lcd.print("RGB");
  37. lcd.setCursor(0,1);
  38. lcd.print("R:");
  39. lcd.print(Pot_3_red);
  40. lcd.setCursor(5,1);
  41. lcd.print("B:");
  42. lcd.print(Pot_1_blue);
  43. lcd.setCursor(11,1);
  44. lcd.print("G:");
  45. lcd.print(Pot_2_green);
  46. delay(100);
  47. lcd.clear();
  48. clearLCD();
  49. }
  50.  
  51. void clearLCD()
  52. {
  53. if(Pot_3_red<100)
  54. {
  55. lcd.setCursor(4,0);
  56. lcd.print("");
  57. }else if(Pot_3_red<10)
  58. {
  59. lcd.setCursor(3,0);
  60. lcd.print("");
  61. }
  62.  
  63. if(Pot_1_blue<100)
  64. {
  65. lcd.setCursor(9,0);
  66. lcd.print("");
  67. }else if(Pot_3_red<10)
  68. {
  69. lcd.setCursor(8,0);
  70. lcd.print("");
  71. }
  72.  
  73. if(Pot_2_green<100)
  74. {
  75. lcd.setCursor(15,0);
  76. lcd.print("");
  77. }else if(Pot_3_red<10)
  78. {
  79. lcd.setCursor(14,0);
  80. lcd.print("");
  81. }
  82.  
  83. }
  84.  
  85.  
  86.  
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement