GY-63_MS5611/libraries/I2C_LCD/I2C_LCD.h

131 lines
3.2 KiB
C
Raw Normal View History

2023-12-17 07:01:57 -05:00
#pragma once
//
// FILE: I2C_LCD.h
2024-01-03 05:05:18 -05:00
// AUTHOR: Rob.Tillaart
2024-08-26 11:51:51 -04:00
// VERSION: 0.2.2
2023-12-17 07:01:57 -05:00
// DATE: 2023-12-16
2024-01-03 05:05:18 -05:00
// PURPOSE: Arduino library for I2C_LCD
2023-12-17 07:01:57 -05:00
// URL: https://github.com/RobTillaart/I2C_LCD
2024-08-26 11:51:51 -04:00
#define I2C_LCD_LIB_VERSION (F("0.2.2"))
2024-01-10 15:21:56 -05:00
2023-12-17 07:01:57 -05:00
#include "Arduino.h"
#include "Wire.h"
2023-12-30 08:25:00 -05:00
const uint8_t POSITIVE = 1;
const uint8_t NEGATIVE = 0;
2023-12-20 15:07:32 -05:00
2023-12-17 07:01:57 -05:00
class I2C_LCD : public Print
{
public:
2023-12-20 15:07:32 -05:00
// only one constructor
2023-12-17 07:01:57 -05:00
explicit I2C_LCD(uint8_t address, TwoWire * wire = &Wire);
2023-12-20 15:07:32 -05:00
// adjust pins
2023-12-24 02:18:11 -05:00
void config(uint8_t address, uint8_t enable, uint8_t readWrite, uint8_t registerSelect,
2023-12-20 15:07:32 -05:00
uint8_t data4, uint8_t data5, uint8_t data6, uint8_t data7,
2023-12-21 13:55:56 -05:00
uint8_t backLight, uint8_t polarity);
2023-12-17 07:01:57 -05:00
2023-12-20 15:07:32 -05:00
// only supports 5x8 char set for now.
2023-12-30 08:25:00 -05:00
// blocks up to 100 milliseconds to give LCD time to boot
bool begin(uint8_t cols = 20, uint8_t rows = 4);
2023-12-20 15:07:32 -05:00
bool isConnected();
2023-12-17 07:01:57 -05:00
2023-12-20 15:07:32 -05:00
// BACKLIGHT
2023-12-21 13:55:56 -05:00
void setBacklightPin(uint8_t pin, uint8_t polarity);
2023-12-20 15:07:32 -05:00
void setBacklight(bool on);
void backlight() { setBacklight(true); };
void noBacklight() { setBacklight(false); };
2023-12-17 07:01:57 -05:00
2023-12-20 15:07:32 -05:00
// DISPLAY ON OFF
2023-12-17 07:01:57 -05:00
void display();
void noDisplay();
2023-12-20 15:07:32 -05:00
void on() { display(); };
void off() { noDisplay(); };
2023-12-24 02:18:11 -05:00
2023-12-17 07:01:57 -05:00
2023-12-20 15:07:32 -05:00
// POSITIONING & CURSOR
void clear(); // clears whole screen
void clearEOL(); // clears line from current pos.
2023-12-17 07:01:57 -05:00
void home();
2023-12-20 15:07:32 -05:00
bool setCursor(uint8_t col, uint8_t row);
void noBlink();
void blink();
void noCursor();
void cursor();
void scrollDisplayLeft();
void scrollDisplayRight();
2023-12-24 02:18:11 -05:00
void moveCursorRight(uint8_t n = 1);
void moveCursorLeft(uint8_t n = 1);
2023-12-20 15:07:32 -05:00
// next 4 limited support
void autoscroll();
void noAutoscroll();
void leftToRight();
void rightToLeft();
2023-12-17 07:01:57 -05:00
2023-12-20 15:07:32 -05:00
// 8 definable characters
void createChar(uint8_t index, uint8_t * charmap);
// clean way to print them
inline size_t special(uint8_t index) { return write((uint8_t)index); };
2023-12-17 07:01:57 -05:00
2023-12-21 13:55:56 -05:00
// PRINT INTERFACE ++
2023-12-17 07:01:57 -05:00
size_t write(uint8_t c);
2023-12-21 13:55:56 -05:00
size_t center(uint8_t row, const char * message);
size_t right(uint8_t col, uint8_t row, const char * message);
2023-12-30 08:25:00 -05:00
size_t repeat(uint8_t c, uint8_t times);
2023-12-17 07:01:57 -05:00
2023-12-20 15:07:32 -05:00
// DEBUG development
uint8_t getColumn() { return _pos; }; // works.
uint32_t getWriteCount() { return _count; }; // works
private:
2023-12-17 07:01:57 -05:00
void sendData(uint8_t value);
void sendCommand(uint8_t value);
2023-12-21 13:55:56 -05:00
void send(uint8_t value, bool dataFlag);
2023-12-17 07:01:57 -05:00
void write4bits(uint8_t value);
uint8_t _address = 0;
TwoWire * _wire = NULL;
2023-12-20 15:07:32 -05:00
uint8_t _enable = 4;
uint8_t _readWrite = 2;
uint8_t _registerSelect = 1;
2023-12-17 07:01:57 -05:00
2024-01-03 05:05:18 -05:00
uint8_t _dataPin[4] = { 16, 32, 64, 128 }; // == pin 4, 5, 6, 7
// minor optimization only for pins = 4,5,6,7
2024-01-10 15:21:56 -05:00
bool _pin4567 = true;
2023-12-20 15:07:32 -05:00
uint8_t _backLightPin = 8;
uint8_t _backLightPol = 1;
uint8_t _backLight = 1;
2023-12-17 07:01:57 -05:00
uint8_t _cols = 20;
uint8_t _rows = 4;
2023-12-24 02:18:11 -05:00
2023-12-20 15:07:32 -05:00
// DISPLAYCONTROL bit always on, set in constructor.
uint8_t _displayControl = 0;
// overflow protection
uint8_t _pos = 0;
uint32_t _count = 0;
2023-12-17 07:01:57 -05:00
};
// -- END OF FILE --