You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

lcd.cpp 1.8KB

3 kuukautta sitten
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #include "lcd.h"
  2. LCD::LCD() {}
  3. LCD::~LCD() {
  4. delete lcd;
  5. }
  6. void LCD::init() {
  7. lcd = new LiquidCrystal_I2C(0x27, columns, rows);
  8. lcd->init();
  9. lcd->backlight();
  10. lcd->setBacklight(HIGH);
  11. }
  12. void LCD::print_init_message(int calibration_weight) const {
  13. lcd->setCursor(0, 0);
  14. lcd->print(F("YCM Scale"));
  15. lcd->setCursor(0, 1);
  16. lcd->print(F("Scaled to: "));
  17. lcd->print(calibration_weight);
  18. lcd->print(F("g"));
  19. delay(1500);
  20. }
  21. void LCD::print_calibration(int calib_weight) const {
  22. lcd->setCursor(0, 1);
  23. lcd->print("Calibration: ");
  24. lcd->print(calib_weight);
  25. lcd->print(" g");
  26. delay(800);
  27. clear_row(1);
  28. }
  29. void LCD::print_weight(double weight, int precision, const char* unit) const {
  30. //
  31. // MAKE SURE NEGATIVE AND POSITIVE VALUES DON'T JUMP
  32. //
  33. if (weight > 0) {
  34. lcd->print(" ");
  35. }
  36. //
  37. // PRINT
  38. //
  39. lcd->print(weight, precision);
  40. lcd->print(" ");
  41. lcd->print(unit);
  42. }
  43. void LCD::print_weights(double grams, double grains) const {
  44. lcd->setCursor(0, 0);
  45. print_weight(grams, 3, "g ");
  46. lcd->setCursor(0, 1);
  47. print_weight(grains, 2, "grn ");
  48. }
  49. void LCD::print_control_result(String name, double val_min, double val_max, int result) {
  50. lcd->setCursor(0, 0);
  51. lcd->print(name);
  52. lcd->print(" ");
  53. lcd->print(val_min, 2);
  54. lcd->print("-");
  55. lcd->print(val_max, 2);
  56. lcd->setCursor(0, 1);
  57. if (result == -1) {
  58. lcd->print("TOO LITTLE");
  59. }
  60. else if (result == 1) {
  61. lcd->print("TOO MUCH ");
  62. }
  63. else {
  64. lcd->print("PASSED ");
  65. }
  66. }
  67. void LCD::clear_row(int row) const {
  68. lcd->setCursor(0, row);
  69. for (int i = 0; i < columns; i++) {
  70. lcd->print(" ");
  71. }
  72. lcd->setCursor(0, row);
  73. }
  74. void LCD::clear() const {
  75. lcd->clear();
  76. }