LCD__code.ino 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Get the LCD I2C Library here:
  2. // https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
  3. // SDA....>A4
  4. // SCL....>A5
  5. #include <LiquidCrystal_I2C.h>
  6. #include <Wire.h>
  7. byte solar[8] = //icon for termometer
  8. {
  9. 0b11111,
  10. 0b10101,
  11. 0b11111,
  12. 0b10101,
  13. 0b11111,
  14. 0b10101,
  15. 0b11111,
  16. 0b00000
  17. };
  18. byte battery[8]=
  19. {
  20. 0b01110,
  21. 0b11011,
  22. 0b10001,
  23. 0b10001,
  24. 0b11111,
  25. 0b11111,
  26. 0b11111,
  27. 0b11111,
  28. };
  29. byte pwm [8]=
  30. {
  31. 0b11101,
  32. 0b10101,
  33. 0b10101,
  34. 0b10101,
  35. 0b10101,
  36. 0b10101,
  37. 0b10101,
  38. 0b10111,
  39. };
  40. // set the LCD address to 0x27 for a 20 chars 4 line display
  41. // Set the pins on the I2C chip used for LCD connections:
  42. // addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
  43. LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
  44. int backlight_Pin = 5;
  45. int backlight_State = 0;
  46. void setup() /*----( SETUP: RUNS ONCE )----*/
  47. {
  48. Serial.begin(9600); // Used to type in characters
  49. pinMode(backlight_Pin, INPUT);
  50. lcd.begin(20,4); // initialize the lcd for 16 chars 2 lines, turn on backlight
  51. lcd.noBacklight();
  52. lcd.createChar(1,solar);
  53. lcd.createChar(2, battery);
  54. lcd.createChar(3, pwm);
  55. //-------- Write characters on the display ------------------
  56. // NOTE: Cursor Position: (CHAR, LINE) start at 0
  57. lcd.clear();
  58. }/*--(end setup )---*/
  59. void loop()
  60. {
  61. symbol();
  62. backlight_State = digitalRead(backlight_Pin);
  63. if ( backlight_State == HIGH)
  64. {
  65. lcd.backlight();// finish with backlight on
  66. // Wait for 10 seconds and then turn off the display and backlight.
  67. delay(10000); // adjust back light on time
  68. lcd.noBacklight();
  69. }
  70. }
  71. void symbol()
  72. {
  73. lcd.setCursor(0, 0);
  74. lcd.print("SOL");
  75. lcd.setCursor(4, 0);
  76. lcd.write(1);
  77. lcd.setCursor(0, 1);
  78. lcd.print("16.45V");
  79. lcd.setCursor(0, 2);
  80. lcd.print("1.03A");
  81. lcd.setCursor(0, 3);
  82. lcd.print("16.94W");
  83. lcd.setCursor(8, 0);
  84. lcd.print("BAT");
  85. lcd.setCursor(12, 0);
  86. lcd.write(2);
  87. lcd.setCursor(8, 1);
  88. lcd.print("12.35V");
  89. lcd.setCursor(8,2);
  90. lcd.print("bulk");
  91. lcd.setCursor(8,3);
  92. lcd.print( "70%");
  93. lcd.setCursor(15,0);
  94. lcd.print("PWM");
  95. lcd.setCursor(19,0);
  96. lcd.write(3);
  97. lcd.setCursor(15,1);
  98. lcd.print("95%");
  99. lcd.setCursor(15,2);
  100. lcd.print("Load");
  101. lcd.setCursor(15,3);
  102. lcd.print("Off");
  103. }