Advertisement
kgofhedgehogs

Untitled

Jan 17th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.98 KB | None | 0 0
  1. /*
  2.   rgb_lcd.h
  3.   2013 Copyright (c) Seeed Technology Inc.  All right reserved.
  4.  
  5.   Author:Loovee
  6.   2013-9-18
  7.  
  8.   add rgb backlight fucnction @ 2013-10-15
  9.  
  10.   The MIT License (MIT)
  11.  
  12.   Permission is hereby granted, free of charge, to any person obtaining a copy
  13.   of this software and associated documentation files (the "Software"), to deal
  14.   in the Software without restriction, including without limitation the rights
  15.   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  16.   copies of the Software, and to permit persons to whom the Software is
  17.   furnished to do so, subject to the following conditions:
  18.  
  19.   The above copyright notice and this permission notice shall be included in
  20.   all copies or substantial portions of the Software.
  21.  
  22.   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  23.   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  24.   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  25.   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  26.   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  27.   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  28.   THE SOFTWARE.1  USA
  29. */
  30.  
  31.  
  32. #ifndef __RGB_LCD_H__
  33. #define __RGB_LCD_H__
  34.  
  35. #include <inttypes.h>
  36. #include "Print.h"
  37.  
  38. // Device I2C Arress
  39. #define LCD_ADDRESS     (0x7c>>1)
  40. #define RGB_ADDRESS     (0xc4>>1)
  41.  
  42.  
  43. // color define
  44. #define WHITE           0
  45. #define RED             1
  46. #define GREEN           2
  47. #define BLUE            3
  48.  
  49. #define REG_RED         0x04        // pwm2
  50. #define REG_GREEN       0x03        // pwm1
  51. #define REG_BLUE        0x02        // pwm0
  52.  
  53. #define REG_MODE1       0x00
  54. #define REG_MODE2       0x01
  55. #define REG_OUTPUT      0x08
  56.  
  57. // commands
  58. #define LCD_CLEARDISPLAY 0x01
  59. #define LCD_RETURNHOME 0x02
  60. #define LCD_ENTRYMODESET 0x04
  61. #define LCD_DISPLAYCONTROL 0x08
  62. #define LCD_CURSORSHIFT 0x10
  63. #define LCD_FUNCTIONSET 0x20
  64. #define LCD_SETCGRAMADDR 0x40
  65. #define LCD_SETDDRAMADDR 0x80
  66.  
  67. // flags for display entry mode
  68. #define LCD_ENTRYRIGHT 0x00
  69. #define LCD_ENTRYLEFT 0x02
  70. #define LCD_ENTRYSHIFTINCREMENT 0x01
  71. #define LCD_ENTRYSHIFTDECREMENT 0x00
  72.  
  73. // flags for display on/off control
  74. #define LCD_DISPLAYON 0x04
  75. #define LCD_DISPLAYOFF 0x00
  76. #define LCD_CURSORON 0x02
  77. #define LCD_CURSOROFF 0x00
  78. #define LCD_BLINKON 0x01
  79. #define LCD_BLINKOFF 0x00
  80.  
  81. // flags for display/cursor shift
  82. #define LCD_DISPLAYMOVE 0x08
  83. #define LCD_CURSORMOVE 0x00
  84. #define LCD_MOVERIGHT 0x04
  85. #define LCD_MOVELEFT 0x00
  86.  
  87. // flags for function set
  88. #define LCD_8BITMODE 0x10
  89. #define LCD_4BITMODE 0x00
  90. #define LCD_2LINE 0x08
  91. #define LCD_1LINE 0x00
  92. #define LCD_5x10DOTS 0x04
  93. #define LCD_5x8DOTS 0x00
  94.  
  95. class rgb_lcd : public Print
  96. {
  97.  
  98. public:
  99.   rgb_lcd();
  100.  
  101.   void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS);
  102.  
  103.   void clear();
  104.   void home();
  105.  
  106.   void noDisplay();
  107.   void display();
  108.   void noBlink();
  109.   void blink();
  110.   void noCursor();
  111.   void cursor();
  112.   void scrollDisplayLeft();
  113.   void scrollDisplayRight();
  114.   void leftToRight();
  115.   void rightToLeft();
  116.   void autoscroll();
  117.   void noAutoscroll();
  118.  
  119.   void createChar(uint8_t, uint8_t[]);
  120.   void setCursor(uint8_t, uint8_t);
  121.  
  122.   virtual size_t write(uint8_t);
  123.   void command(uint8_t);
  124.  
  125.   // color control
  126.   void setRGB(unsigned char r, unsigned char g, unsigned char b);               // set rgb
  127.   void setPWM(unsigned char color, unsigned char pwm){setReg(color, pwm);}      // set pwm
  128.  
  129.   void setColor(unsigned char color);
  130.   void setColorAll(){setRGB(0, 0, 0);}
  131.   void setColorWhite(){setRGB(255, 255, 255);}
  132.  
  133.   // blink the LED backlight
  134.   void blinkLED(void);
  135.   void noBlinkLED(void);
  136.  
  137.   using Print::write;
  138.  
  139. private:
  140.   void send(uint8_t, uint8_t);
  141.   void setReg(unsigned char addr, unsigned char dta);
  142.  
  143.   uint8_t _displayfunction;
  144.   uint8_t _displaycontrol;
  145.   uint8_t _displaymode;
  146.  
  147.   uint8_t _initialized;
  148.  
  149.   uint8_t _numlines,_currline;
  150. };
  151.  
  152. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement