├── .gitlab-ci.yml ├── library.properties ├── .travis.yml ├── .gitattributes ├── .github └── workflows │ ├── stale.yml │ ├── sync_issues.yml │ └── run-ci-arduino.yml ├── keywords.txt ├── License.txt ├── examples ├── Cursor │ └── Cursor.ino ├── Display │ └── Display.ino ├── Blink │ └── Blink.ino ├── fade │ └── fade.ino ├── HelloWorld │ └── HelloWorld.ino ├── SerialDisplay │ └── SerialDisplay.ino ├── setCursor │ └── setCursor.ino ├── Autoscroll │ └── Autoscroll.ino ├── TextDirection │ └── TextDirection.ino ├── setColor │ └── setColor.ino ├── Scroll │ └── Scroll.ino ├── CustomCharacter │ └── CustomCharacter.ino └── CustomCharacterProgmem │ └── CustomCharacterProgmem.ino ├── .gitignore ├── README.md ├── rgb_lcd.h └── rgb_lcd.cpp /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | build: 2 | tags: 3 | - nas 4 | script: 5 | - wget -c https://files.seeedstudio.com/arduino/seeed-arduino-ci.sh 6 | - chmod +x seeed-arduino-ci.sh 7 | - bash $PWD/seeed-arduino-ci.sh test 8 | 9 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=Grove - LCD RGB Backlight 2 | version=1.0.2 3 | author=Seeed Studio 4 | maintainer=Seeed Studio 5 | sentence=Arduino library to control Grove - LCD RGB Backlight. 6 | paragraph=Arduino library to control Grove - LCD RGB Backlight. 7 | category=Display 8 | url=https://github.com/Seeed-Studio/Grove_LCD_RGB_Backlight 9 | architectures=* 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | 2 | language: generic 3 | dist: bionic 4 | sudo: false 5 | cache: 6 | directories: 7 | - ~/arduino_ide 8 | - ~/.arduino15/packages/ 9 | 10 | before_install: 11 | - wget -c https://files.seeedstudio.com/arduino/seeed-arduino-ci.sh 12 | 13 | script: 14 | - chmod +x seeed-arduino-ci.sh 15 | - cat $PWD/seeed-arduino-ci.sh 16 | - bash $PWD/seeed-arduino-ci.sh test 17 | 18 | notifications: 19 | email: 20 | on_success: change 21 | on_failure: change 22 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | name: 'Close stale issues and PRs' 2 | 3 | on: 4 | workflow_dispatch: 5 | schedule: 6 | - cron: '0 4 * * *' 7 | 8 | jobs: 9 | stale: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - name: Checkout repository 14 | uses: actions/checkout@v4 15 | 16 | - name: Checkout script repository 17 | uses: actions/checkout@v4 18 | with: 19 | repository: Seeed-Studio/sync-github-all-issues 20 | path: ci 21 | 22 | - name: Run script 23 | run: ./ci/tools/stale.sh 24 | env: 25 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 26 | -------------------------------------------------------------------------------- /.github/workflows/sync_issues.yml: -------------------------------------------------------------------------------- 1 | name: Automate Issue Management 2 | 3 | on: 4 | issues: 5 | types: 6 | - opened 7 | - edited 8 | - assigned 9 | - unassigned 10 | - labeled 11 | - unlabeled 12 | - reopened 13 | 14 | jobs: 15 | add_issue_to_project: 16 | runs-on: ubuntu-latest 17 | steps: 18 | - name: Add issue to GitHub Project 19 | uses: actions/add-to-project@v1.0.2 20 | with: 21 | project-url: https://github.com/orgs/Seeed-Studio/projects/17 22 | github-token: ${{ secrets.ISSUE_ASSEMBLE }} 23 | labeled: bug 24 | label-operator: NOT -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For Grove - Serial LCD GRB BackLight 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | rgb_lcd KEYWORD1 9 | lcd KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | begin KEYWORD2 15 | clear KEYWORD2 16 | home KEYWORD2 17 | display KEYWORD2 18 | noBlink KEYWORD2 19 | blink KEYWORD2 20 | noCursor KEYWORD2 21 | cursor KEYWORD2 22 | scrollDisplayLeft KEYWORD2 23 | scrollDisplayRight KEYWORD2 24 | leftToRight KEYWORD2 25 | rightToLeft KEYWORD2 26 | autoscroll KEYWORD2 27 | noAutoscroll KEYWORD2 28 | createChar KEYWORD2 29 | write KEYWORD2 30 | command KEYWORD2 31 | setRGB KEYWORD2 32 | setPWM KEYWORD2 33 | setColor KEYWORD2 34 | setColorWhite KEYWORD2 35 | 36 | 37 | ####################################### 38 | # Constants (LITERAL1) 39 | ####################################### 40 | I2C_ADDRESS LITERAL1 -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Seeed Technology Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /.github/workflows/run-ci-arduino.yml: -------------------------------------------------------------------------------- 1 | name: Run Ci Arduino 2 | 3 | on: 4 | push: 5 | pull_request: 6 | repository_dispatch: 7 | types: [trigger-workflow] 8 | 9 | jobs: 10 | ci-arduino: 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - name: Checkout repository 15 | uses: actions/checkout@v4 16 | 17 | - name: Checkout script repository 18 | uses: actions/checkout@v4 19 | with: 20 | repository: Seeed-Studio/ci-arduino 21 | path: ci 22 | 23 | - name: Setup arduino cli 24 | uses: arduino/setup-arduino-cli@v2.0.0 25 | 26 | - name: Create a depend.list file 27 | run: | 28 | # eg: echo "" >> depend.list 29 | 30 | - name: Create a ignore.list file 31 | run: | 32 | # eg: echo "," >> ignore.list 33 | 34 | - name: Build sketch 35 | run: ./ci/tools/compile.sh 36 | 37 | - name: Build result 38 | run: | 39 | cat build.log 40 | if [ ${{ github.event_name }} == 'pull_request' ] && [ -f compile.failed ]; then 41 | exit 1 42 | fi 43 | 44 | - name: Generate issue 45 | if: ${{ github.event_name != 'pull_request' }} 46 | run: ./ci/tools/issue.sh 47 | env: 48 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 49 | -------------------------------------------------------------------------------- /examples/Cursor/Cursor.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Cursor.ino 3 | 2013 Copyright (c) Seeed Technology Inc. All right reserved. 4 | 5 | Author:Loovee 6 | 2013-9-18 7 | 8 | Grove - Serial LCD RGB Backlight demo. 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #include 26 | #include "rgb_lcd.h" 27 | 28 | rgb_lcd lcd; 29 | 30 | void setup() { 31 | // set up the LCD's number of columns and rows: 32 | lcd.begin(16, 2); 33 | // Print a message to the LCD. 34 | lcd.print("hello, world!"); 35 | } 36 | 37 | void loop() { 38 | // Turn off the cursor: 39 | lcd.noCursor(); 40 | delay(500); 41 | // Turn on the cursor: 42 | lcd.cursor(); 43 | delay(500); 44 | } 45 | 46 | /********************************************************************************************************* 47 | END FILE 48 | *********************************************************************************************************/ 49 | -------------------------------------------------------------------------------- /examples/Display/Display.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Display.ino 3 | 2013 Copyright (c) Seeed Technology Inc. All right reserved. 4 | 5 | Author:Loovee 6 | 2013-9-18 7 | 8 | Grove - Serial LCD RGB Backlight demo. 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #include 26 | #include "rgb_lcd.h" 27 | 28 | rgb_lcd lcd; 29 | 30 | void setup() { 31 | // set up the LCD's number of columns and rows: 32 | lcd.begin(16, 2); 33 | // Print a message to the LCD. 34 | lcd.print("hello, world!"); 35 | } 36 | 37 | void loop() { 38 | // Turn off the display: 39 | lcd.noDisplay(); 40 | delay(500); 41 | // Turn on the display: 42 | lcd.display(); 43 | delay(500); 44 | } 45 | 46 | /********************************************************************************************************* 47 | END FILE 48 | *********************************************************************************************************/ -------------------------------------------------------------------------------- /examples/Blink/Blink.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Blink.ino 3 | 2013 Copyright (c) Seeed Technology Inc. All right reserved. 4 | 5 | Author:Loovee 6 | 2013-9-18 7 | 8 | Grove - Serial LCD RGB Backlight demo. 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #include 26 | #include "rgb_lcd.h" 27 | 28 | rgb_lcd lcd; 29 | 30 | 31 | void setup() { 32 | // set up the LCD's number of columns and rows: 33 | lcd.begin(16, 2); 34 | 35 | // Print a message to the LCD. 36 | lcd.print("hello, world!"); 37 | 38 | delay(1000); 39 | } 40 | 41 | void loop() { 42 | // Turn off the blinking cursor: 43 | lcd.noBlink(); 44 | delay(3000); 45 | // Turn on the blinking cursor: 46 | lcd.blink(); 47 | delay(3000); 48 | } 49 | 50 | /********************************************************************************************************* 51 | END FILE 52 | *********************************************************************************************************/ -------------------------------------------------------------------------------- /examples/fade/fade.ino: -------------------------------------------------------------------------------- 1 | /* 2 | fade.ino 3 | 2013 Copyright (c) Seeed Technology Inc. All right reserved. 4 | 5 | Author:Loovee 6 | 2013-10-15 7 | 8 | Grove - Serial LCD RGB Backlight demo. 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #include 26 | #include "rgb_lcd.h" 27 | 28 | rgb_lcd lcd; 29 | 30 | void setup() { 31 | // set up the LCD's number of columns and rows: 32 | lcd.begin(16, 2); 33 | // Print a message to the LCD. 34 | lcd.print("fade demo"); 35 | 36 | } 37 | 38 | void breath(unsigned char color) { 39 | 40 | for (int i = 0; i < 255; i++) { 41 | lcd.setPWM(color, i); 42 | delay(5); 43 | } 44 | 45 | delay(500); 46 | for (int i = 254; i >= 0; i--) { 47 | lcd.setPWM(color, i); 48 | delay(5); 49 | } 50 | 51 | delay(500); 52 | } 53 | 54 | void loop() { 55 | breath(RED); 56 | breath(GREEN); 57 | breath(BLUE); 58 | } 59 | 60 | /********************************************************************************************************* 61 | END FILE 62 | *********************************************************************************************************/ -------------------------------------------------------------------------------- /examples/HelloWorld/HelloWorld.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Hello World.ino 3 | 2013 Copyright (c) Seeed Technology Inc. All right reserved. 4 | 5 | Author:Loovee 6 | 2013-9-18 7 | 8 | Grove - Serial LCD RGB Backlight demo. 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #include 26 | #include "rgb_lcd.h" 27 | 28 | rgb_lcd lcd; 29 | 30 | const int colorR = 255; 31 | const int colorG = 0; 32 | const int colorB = 0; 33 | 34 | void setup() { 35 | // set up the LCD's number of columns and rows: 36 | lcd.begin(16, 2); 37 | 38 | lcd.setRGB(colorR, colorG, colorB); 39 | 40 | // Print a message to the LCD. 41 | lcd.print("hello, world!"); 42 | 43 | delay(1000); 44 | } 45 | 46 | void loop() { 47 | // set the cursor to column 0, line 1 48 | // (note: line 1 is the second row, since counting begins with 0): 49 | lcd.setCursor(0, 1); 50 | // print the number of seconds since reset: 51 | lcd.print(millis() / 1000); 52 | 53 | delay(100); 54 | } 55 | 56 | /********************************************************************************************************* 57 | END FILE 58 | *********************************************************************************************************/ -------------------------------------------------------------------------------- /examples/SerialDisplay/SerialDisplay.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SerialDisplay.ino 3 | 2013 Copyright (c) Seeed Technology Inc. All right reserved. 4 | 5 | Author:Loovee 6 | 2013-9-18 7 | 8 | Grove - Serial LCD RGB Backlight demo. 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #include 26 | #include "rgb_lcd.h" 27 | 28 | rgb_lcd lcd; 29 | 30 | void setup() { 31 | // set up the LCD's number of columns and rows: 32 | lcd.begin(16, 2); 33 | // initialize the serial communications: 34 | Serial.begin(9600); 35 | } 36 | 37 | void loop() { 38 | // when characters arrive over the serial port... 39 | if (Serial.available()) { 40 | // wait a bit for the entire message to arrive 41 | delay(100); 42 | // clear the screen 43 | lcd.clear(); 44 | // read all the available characters 45 | while (Serial.available() > 0) { 46 | // display each character to the LCD 47 | lcd.write(Serial.read()); 48 | } 49 | } 50 | } 51 | 52 | /********************************************************************************************************* 53 | END FILE 54 | *********************************************************************************************************/ -------------------------------------------------------------------------------- /examples/setCursor/setCursor.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SerialDisplay.ino 3 | 2013 Copyright (c) Seeed Technology Inc. All right reserved. 4 | 5 | Author:Loovee 6 | 2013-9-18 7 | 8 | Grove - Serial LCD RGB Backlight demo. 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #include 26 | #include "rgb_lcd.h" 27 | 28 | rgb_lcd lcd; 29 | 30 | const int numRows = 2; 31 | const int numCols = 16; 32 | 33 | void setup() { 34 | // set up the LCD's number of columns and rows: 35 | lcd.begin(numCols, numRows); 36 | } 37 | 38 | void loop() { 39 | // loop from ASCII 'a' to ASCII 'z': 40 | for (int thisLetter = 'a'; thisLetter <= 'z'; thisLetter++) { 41 | // loop over the columns: 42 | for (int thisCol = 0; thisCol < numRows; thisCol++) { 43 | // loop over the rows: 44 | for (int thisRow = 0; thisRow < numCols; thisRow++) { 45 | // set the cursor position: 46 | lcd.setCursor(thisRow, thisCol); 47 | // print the letter: 48 | lcd.write(thisLetter); 49 | delay(200); 50 | } 51 | } 52 | } 53 | } 54 | 55 | /********************************************************************************************************* 56 | END FILE 57 | *********************************************************************************************************/ -------------------------------------------------------------------------------- /examples/Autoscroll/Autoscroll.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Autoscroll.ino 3 | 2013 Copyright (c) Seeed Technology Inc. All right reserved. 4 | 5 | Author:Loovee 6 | 2013-9-18 7 | 8 | Grove - Serial LCD RGB Backlight demo. 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #include 26 | #include "rgb_lcd.h" 27 | 28 | rgb_lcd lcd; 29 | 30 | 31 | void setup() { 32 | // set up the LCD's number of columns and rows: 33 | lcd.begin(16, 2); 34 | } 35 | 36 | void loop() { 37 | // set the cursor to (0,0): 38 | lcd.setCursor(0, 0); 39 | // print from 0 to 9: 40 | for (int thisChar = 0; thisChar < 10; thisChar++) { 41 | lcd.print(thisChar); 42 | delay(500); 43 | } 44 | 45 | // set the cursor to (16,1): 46 | lcd.setCursor(16, 1); 47 | // set the display to automatically scroll: 48 | lcd.autoscroll(); 49 | // print from 0 to 9: 50 | for (int thisChar = 0; thisChar < 10; thisChar++) { 51 | lcd.print(thisChar); 52 | delay(500); 53 | } 54 | // turn off automatic scrolling 55 | lcd.noAutoscroll(); 56 | 57 | // clear screen for the next loop: 58 | lcd.clear(); 59 | } 60 | 61 | /********************************************************************************************************* 62 | END FILE 63 | *********************************************************************************************************/ 64 | -------------------------------------------------------------------------------- /examples/TextDirection/TextDirection.ino: -------------------------------------------------------------------------------- 1 | /* 2 | TextDirection.ino 3 | 2013 Copyright (c) Seeed Technology Inc. All right reserved. 4 | 5 | Author:Loovee 6 | 2013-9-18 7 | 8 | Grove - Serial LCD RGB Backlight demo. 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #include 26 | #include "rgb_lcd.h" 27 | 28 | rgb_lcd lcd; 29 | 30 | int thisChar = 'a'; 31 | 32 | void setup() { 33 | // set up the LCD's number of columns and rows: 34 | lcd.begin(16, 2); 35 | // turn on the cursor: 36 | lcd.cursor(); 37 | } 38 | 39 | void loop() { 40 | // reverse directions at 'm': 41 | if (thisChar == 'm') { 42 | // go right for the next letter 43 | lcd.rightToLeft(); 44 | } 45 | // reverse again at 's': 46 | if (thisChar == 's') { 47 | // go left for the next letter 48 | lcd.leftToRight(); 49 | } 50 | // reset at 'z': 51 | if (thisChar > 'z') { 52 | // go to (0,0): 53 | lcd.home(); 54 | // start again at 0 55 | thisChar = 'a'; 56 | } 57 | // print the character 58 | lcd.write(thisChar); 59 | // wait a second: 60 | delay(1000); 61 | // increment the letter: 62 | thisChar++; 63 | } 64 | 65 | /********************************************************************************************************* 66 | END FILE 67 | *********************************************************************************************************/ -------------------------------------------------------------------------------- /examples/setColor/setColor.ino: -------------------------------------------------------------------------------- 1 | /* 2 | setColor.ino 3 | 2013 Copyright (c) Seeed Technology Inc. All right reserved. 4 | 5 | Author:Loovee 6 | 2013-10-15 7 | 8 | Grove - Serial LCD RGB Backlight demo. 9 | you can set color by serial input, input "rrr ggg bbb" 10 | 11 | rrr means red, 0-255, eg: 005, 015, 135 12 | ggg means green 13 | bbb means blue 14 | 15 | This library is free software; you can redistribute it and/or 16 | modify it under the terms of the GNU Lesser General Public 17 | License as published by the Free Software Foundation; either 18 | version 2.1 of the License, or (at your option) any later version. 19 | 20 | This library is distributed in the hope that it will be useful, 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | Lesser General Public License for more details. 24 | 25 | You should have received a copy of the GNU Lesser General Public 26 | License along with this library; if not, write to the Free Software 27 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 28 | */ 29 | 30 | #include 31 | #include "rgb_lcd.h" 32 | 33 | rgb_lcd lcd; 34 | 35 | char dtaUart[15]; 36 | char dtaLen = 0; 37 | 38 | void setup() { 39 | Serial.begin(115200); 40 | // set up the LCD's number of columns and rows: 41 | lcd.begin(16, 2); 42 | // Print a message to the LCD. 43 | lcd.print("set cllor"); 44 | } 45 | 46 | void loop() { 47 | 48 | if (dtaLen == 11) { 49 | int r = (dtaUart[0] - '0') * 100 + (dtaUart[1] - '0') * 10 + (dtaUart[2] - '0'); // get r 50 | int g = (dtaUart[4] - '0') * 100 + (dtaUart[5] - '0') * 10 + (dtaUart[6] - '0'); 51 | int b = (dtaUart[8] - '0') * 100 + (dtaUart[9] - '0') * 10 + (dtaUart[10] - '0'); 52 | 53 | dtaLen = 0; 54 | 55 | lcd.setRGB(r, g, b); 56 | 57 | Serial.println("get data"); 58 | 59 | Serial.println(r); 60 | Serial.println(g); 61 | Serial.println(b); 62 | Serial.println(); 63 | 64 | } 65 | } 66 | 67 | void serialEvent() { 68 | while (Serial.available()) { 69 | dtaUart[dtaLen++] = Serial.read(); 70 | } 71 | } 72 | 73 | /********************************************************************************************************* 74 | END FILE 75 | *********************************************************************************************************/ -------------------------------------------------------------------------------- /examples/Scroll/Scroll.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Hello World.ino 3 | 2013 Copyright (c) Seeed Technology Inc. All right reserved. 4 | 5 | Author:Loovee 6 | 2013-9-18 7 | 8 | Grove - Serial LCD RGB Backlight demo. 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #include 26 | #include "rgb_lcd.h" 27 | 28 | rgb_lcd lcd; 29 | 30 | void setup() { 31 | // set up the LCD's number of columns and rows: 32 | lcd.begin(16, 2); 33 | // Print a message to the LCD. 34 | lcd.print("hello, world!"); 35 | delay(1000); 36 | } 37 | 38 | void loop() { 39 | // scroll 13 positions (string length) to the left 40 | // to move it offscreen left: 41 | for (int positionCounter = 0; positionCounter < 13; positionCounter++) { 42 | // scroll one position left: 43 | lcd.scrollDisplayLeft(); 44 | // wait a bit: 45 | delay(150); 46 | } 47 | 48 | // scroll 29 positions (string length + display length) to the right 49 | // to move it offscreen right: 50 | for (int positionCounter = 0; positionCounter < 29; positionCounter++) { 51 | // scroll one position right: 52 | lcd.scrollDisplayRight(); 53 | // wait a bit: 54 | delay(150); 55 | } 56 | 57 | // scroll 16 positions (display length + string length) to the left 58 | // to move it back to center: 59 | for (int positionCounter = 0; positionCounter < 16; positionCounter++) { 60 | // scroll one position left: 61 | lcd.scrollDisplayLeft(); 62 | // wait a bit: 63 | delay(150); 64 | } 65 | 66 | // delay at the end of the full loop: 67 | delay(1000); 68 | 69 | } 70 | 71 | /********************************************************************************************************* 72 | END FILE 73 | *********************************************************************************************************/ -------------------------------------------------------------------------------- /examples/CustomCharacter/CustomCharacter.ino: -------------------------------------------------------------------------------- 1 | /* 2 | CustomCharacter.ino 3 | 2013 Copyright (c) Seeed Technology Inc. All right reserved. 4 | 5 | Author:Loovee 6 | 2013-9-18 7 | 8 | Grove - Serial LCD RGB Backlight demo. 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #include 26 | #include "rgb_lcd.h" 27 | 28 | rgb_lcd lcd; 29 | 30 | // make some custom characters: 31 | byte heart[8] = { 32 | 0b00000, 33 | 0b01010, 34 | 0b11111, 35 | 0b11111, 36 | 0b11111, 37 | 0b01110, 38 | 0b00100, 39 | 0b00000 40 | }; 41 | 42 | byte smiley[8] = { 43 | 0b00000, 44 | 0b00000, 45 | 0b01010, 46 | 0b00000, 47 | 0b00000, 48 | 0b10001, 49 | 0b01110, 50 | 0b00000 51 | }; 52 | 53 | byte frownie[8] = { 54 | 0b00000, 55 | 0b00000, 56 | 0b01010, 57 | 0b00000, 58 | 0b00000, 59 | 0b00000, 60 | 0b01110, 61 | 0b10001 62 | }; 63 | 64 | byte armsDown[8] = { 65 | 0b00100, 66 | 0b01010, 67 | 0b00100, 68 | 0b00100, 69 | 0b01110, 70 | 0b10101, 71 | 0b00100, 72 | 0b01010 73 | }; 74 | 75 | byte armsUp[8] = { 76 | 0b00100, 77 | 0b01010, 78 | 0b00100, 79 | 0b10101, 80 | 0b01110, 81 | 0b00100, 82 | 0b00100, 83 | 0b01010 84 | }; 85 | 86 | 87 | void setup() { 88 | 89 | lcd.begin(16, 2); 90 | #if 1 91 | // create a new character 92 | lcd.createChar(0, heart); 93 | // create a new character 94 | lcd.createChar(1, smiley); 95 | // create a new character 96 | lcd.createChar(2, frownie); 97 | // create a new character 98 | lcd.createChar(3, armsDown); 99 | // create a new character 100 | lcd.createChar(4, armsUp); 101 | #endif 102 | // set up the lcd's number of columns and rows: 103 | 104 | 105 | lcd.setCursor(0, 0); 106 | // Print a message to the lcd. 107 | lcd.print("I "); 108 | lcd.write((unsigned char)0); 109 | lcd.print(" Arduino! "); 110 | lcd.write(1); 111 | } 112 | 113 | void loop() { 114 | // read the potentiometer on A0: 115 | int sensorReading = analogRead(A0); 116 | // map the result to 200 - 1000: 117 | int delayTime = map(sensorReading, 0, 1023, 200, 1000); 118 | // set the cursor to the bottom row, 5th position: 119 | lcd.setCursor(4, 1); 120 | // draw the little man, arms down: 121 | lcd.write(3); 122 | delay(delayTime); 123 | lcd.setCursor(4, 1); 124 | // draw him arms up: 125 | lcd.write(4); 126 | delay(delayTime); 127 | } 128 | 129 | /********************************************************************************************************* 130 | END FILE 131 | *********************************************************************************************************/ -------------------------------------------------------------------------------- /examples/CustomCharacterProgmem/CustomCharacterProgmem.ino: -------------------------------------------------------------------------------- 1 | /* 2 | CustomCharacter.ino 3 | 2013 Copyright (c) Seeed Technology Inc. All right reserved. 4 | 5 | Author:Loovee 6 | 2013-9-18 7 | 8 | Grove - Serial LCD RGB Backlight demo. 9 | 10 | This library is free software; you can redistribute it and/or 11 | modify it under the terms of the GNU Lesser General Public 12 | License as published by the Free Software Foundation; either 13 | version 2.1 of the License, or (at your option) any later version. 14 | 15 | This library is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | Lesser General Public License for more details. 19 | 20 | You should have received a copy of the GNU Lesser General Public 21 | License along with this library; if not, write to the Free Software 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | #include 26 | #include "rgb_lcd.h" 27 | 28 | rgb_lcd lcd; 29 | 30 | // make some custom characters: 31 | const byte heart[8] PROGMEM = { 32 | 0b00000, 33 | 0b01010, 34 | 0b11111, 35 | 0b11111, 36 | 0b11111, 37 | 0b01110, 38 | 0b00100, 39 | 0b00000 40 | }; 41 | 42 | const byte smiley[8] PROGMEM = { 43 | 0b00000, 44 | 0b00000, 45 | 0b01010, 46 | 0b00000, 47 | 0b00000, 48 | 0b10001, 49 | 0b01110, 50 | 0b00000 51 | }; 52 | 53 | const byte frownie[8] PROGMEM = { 54 | 0b00000, 55 | 0b00000, 56 | 0b01010, 57 | 0b00000, 58 | 0b00000, 59 | 0b00000, 60 | 0b01110, 61 | 0b10001 62 | }; 63 | 64 | const byte armsDown[8] PROGMEM = { 65 | 0b00100, 66 | 0b01010, 67 | 0b00100, 68 | 0b00100, 69 | 0b01110, 70 | 0b10101, 71 | 0b00100, 72 | 0b01010 73 | }; 74 | 75 | const byte armsUp[8] PROGMEM = { 76 | 0b00100, 77 | 0b01010, 78 | 0b00100, 79 | 0b10101, 80 | 0b01110, 81 | 0b00100, 82 | 0b00100, 83 | 0b01010 84 | }; 85 | 86 | 87 | void setup() { 88 | 89 | lcd.begin(16, 2); 90 | #if 1 91 | // create a new character 92 | lcd.createCharFromProgmem(0, heart); 93 | // create a new character 94 | lcd.createCharFromProgmem(1, smiley); 95 | // create a new character 96 | lcd.createCharFromProgmem(2, frownie); 97 | // create a new character 98 | lcd.createCharFromProgmem(3, armsDown); 99 | // create a new character 100 | lcd.createCharFromProgmem(4, armsUp); 101 | #endif 102 | // set up the lcd's number of columns and rows: 103 | 104 | 105 | lcd.setCursor(0, 0); 106 | // Print a message to the lcd. 107 | lcd.print("I "); 108 | lcd.write((unsigned char)0); 109 | lcd.print(" Arduino! "); 110 | lcd.write(1); 111 | } 112 | 113 | void loop() { 114 | // read the potentiometer on A0: 115 | int sensorReading = analogRead(A0); 116 | // map the result to 200 - 1000: 117 | int delayTime = map(sensorReading, 0, 1023, 200, 1000); 118 | // set the cursor to the bottom row, 5th position: 119 | lcd.setCursor(4, 1); 120 | // draw the little man, arms down: 121 | lcd.write(3); 122 | delay(delayTime); 123 | lcd.setCursor(4, 1); 124 | // draw him arms up: 125 | lcd.write(4); 126 | delay(delayTime); 127 | } 128 | 129 | /********************************************************************************************************* 130 | END FILE 131 | *********************************************************************************************************/ -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | 46 | [Dd]ebug/ 47 | [Rr]elease/ 48 | x64/ 49 | build/ 50 | [Bb]in/ 51 | [Oo]bj/ 52 | 53 | # MSTest test Results 54 | [Tt]est[Rr]esult*/ 55 | [Bb]uild[Ll]og.* 56 | 57 | *_i.c 58 | *_p.c 59 | *.ilk 60 | *.meta 61 | *.obj 62 | *.pch 63 | *.pdb 64 | *.pgc 65 | *.pgd 66 | *.rsp 67 | *.sbr 68 | *.tlb 69 | *.tli 70 | *.tlh 71 | *.tmp 72 | *.tmp_proj 73 | *.log 74 | *.vspscc 75 | *.vssscc 76 | .builds 77 | *.pidb 78 | *.log 79 | *.scc 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | 101 | # TeamCity is a build add-in 102 | _TeamCity* 103 | 104 | # DotCover is a Code Coverage Tool 105 | *.dotCover 106 | 107 | # NCrunch 108 | *.ncrunch* 109 | .*crunch*.local.xml 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.Publish.xml 129 | *.pubxml 130 | 131 | # NuGet Packages Directory 132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 133 | #packages/ 134 | 135 | # Windows Azure Build Output 136 | csx 137 | *.build.csdef 138 | 139 | # Windows Store app package directory 140 | AppPackages/ 141 | 142 | # Others 143 | sql/ 144 | *.Cache 145 | ClientBin/ 146 | [Ss]tyle[Cc]op.* 147 | ~$* 148 | *~ 149 | *.dbmdl 150 | *.[Pp]ublish.xml 151 | *.pfx 152 | *.publishsettings 153 | 154 | # RIA/Silverlight projects 155 | Generated_Code/ 156 | 157 | # Backup & report files from converting an old project file to a newer 158 | # Visual Studio version. Backup files are not needed, because we have git ;-) 159 | _UpgradeReport_Files/ 160 | Backup*/ 161 | UpgradeLog*.XML 162 | UpgradeLog*.htm 163 | 164 | # SQL Server files 165 | App_Data/*.mdf 166 | App_Data/*.ldf 167 | 168 | ############# 169 | ## Windows detritus 170 | ############# 171 | 172 | # Windows image file caches 173 | Thumbs.db 174 | ehthumbs.db 175 | 176 | # Folder config file 177 | Desktop.ini 178 | 179 | # Recycle Bin used on file shares 180 | $RECYCLE.BIN/ 181 | 182 | # Mac crap 183 | .DS_Store 184 | 185 | 186 | ############# 187 | ## Python 188 | ############# 189 | 190 | *.py[co] 191 | 192 | # Packages 193 | *.egg 194 | *.egg-info 195 | dist/ 196 | build/ 197 | eggs/ 198 | parts/ 199 | var/ 200 | sdist/ 201 | develop-eggs/ 202 | .installed.cfg 203 | 204 | # Installer logs 205 | pip-log.txt 206 | 207 | # Unit test / coverage reports 208 | .coverage 209 | .tox 210 | 211 | #Translations 212 | *.mo 213 | 214 | #Mr Developer 215 | .mr.developer.cfg 216 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Grove - LCD RGB Backlight [![Build Status](https://travis-ci.com/Seeed-Studio/Grove_LCD_RGB_Backlight.svg?branch=master)](https://travis-ci.com/Seeed-Studio/Grove_LCD_RGB_Backlight) 2 | --------------------------------------------------------- 3 | 4 | ![Grove - LCD RGB Backlight](https://raw.githubusercontent.com/SeeedDocument/Grove_LCD_RGB_Backlight/master/images/intro.jpg) 5 | 6 | 7 | [Grove - LCD RGB Backlight](https://www.seeedstudio.com/Grove-LCD-RGB-Backlight-p-1643.html) 8 | 9 | Done with the tedious mono color backlight? This Grove - LCD RBG Backlight enables you to set the color to whatever you like via the simple and concise Grove interface. It takes I2C as the communication method with your microcontroller. The number of pins required for data exchange and backlight control shrinks from ~10 to 2, relieving IOs for other challenging tasks. In addition, Grove - LCD RGB Backlight supports user-defined characters. Want to get a love heart or another custom character? Just take advantage of this feature and design it! 10 | 11 | 12 | ## Usage: 13 | 14 | This is an Arudino Library. It include a .h file, a .cpp file and some examples. Through these examples, you can quickly master the use of Grove - LCD RGB Backlight. 15 | 16 | The in the following, we will introduce some functions which are used very intuitively. 17 | 18 | 19 | ### Initialization 20 | Before we use this lcd, we should initialize it. You can use this function: 21 | 22 | lcd.begin(16, 2); 23 | 24 | This means that this lcd has 16 columns and 2 rows. 25 | 26 | Optionally you can also specify the character size: LCD_5x10DOTS or LCD_5x8DOTS which is the default 27 | 28 | and for those board who support different Wire objects, which one: 29 | 30 | Example: 31 | lcd.begin(16, 2, LCD_5x8DOTS, Wire2); 32 | 33 | 34 | 35 | ### Change Color of Backlight 36 | One of Grove - LCD RGB Backlight's most important feature is changing the backlight color. It's very simple; just use the folowing function: 37 | 38 | void setRGB(int r, int g, int b); 39 | 40 | 41 | ### Clear Display 42 | 43 | You can clear the display by this function: 44 | 45 | void clear(); 46 | 47 | ### Turn on and turn off display 48 | 49 | void noDisplay(); // turn off display 50 | void display(); // turn on display 51 | 52 | ### Blink 53 | 54 | void noBlink(); 55 | void blink(); 56 | 57 | ### Cursor 58 | 59 | void noCursor(); 60 | void cursor(); 61 | 62 | ### Blink LED Backlight 63 | 64 | void noBlinkLED(); 65 | void blinkLED(); 66 | 67 | 68 | For more information, please refer to [wiki page](http://wiki.seeedstudio.com/Grove-LCD_RGB_Backlight/). 69 | 70 | 71 | ---- 72 | 73 | This software is written by loovee([luweicong@seeedstudio.com](luweicong@seeedstudio.com "luweicong@seeedstudio.com")) for seeed studio
74 | and is licensed under [The MIT License](http://opensource.org/licenses/mit-license.php). Check License.txt for more information.
75 | 76 | Contributing to this software is warmly welcomed. You can do this basically by
77 | [forking](https://help.github.com/articles/fork-a-repo), committing modifications and then [pulling requests](https://help.github.com/articles/using-pull-requests) (follow the links above
78 | for operating guide). Adding change log and your contact into file header is encouraged.
79 | Thanks for your contribution. 80 | 81 | Seeed Studio is an open hardware facilitation company based in Shenzhen, China.
82 | Benefiting from local manufacture power and convenient global logistic system,
83 | we integrate resources to serve new era of innovation. Seeed also works with
84 | global distributors and partners to push open hardware movement.
85 | 86 | 87 | 88 | [![Analytics](https://ga-beacon.appspot.com/UA-46589105-3/Grove_LCD_RGB_Backlight)](https://github.com/igrigorik/ga-beacon) 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /rgb_lcd.h: -------------------------------------------------------------------------------- 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 36 | #include "Print.h" 37 | #include 38 | 39 | // Device I2C Arress 40 | #define LCD_ADDRESS (0x7c>>1) 41 | #define RGB_ADDRESS (0xc4>>1) 42 | #define RGB_ADDRESS_V5 (0x30) 43 | 44 | 45 | // color define 46 | #define WHITE 0 47 | #define RED 1 48 | #define GREEN 2 49 | #define BLUE 3 50 | 51 | #define REG_MODE1 0x00 52 | #define REG_MODE2 0x01 53 | #define REG_OUTPUT 0x08 54 | 55 | // commands 56 | #define LCD_CLEARDISPLAY 0x01 57 | #define LCD_RETURNHOME 0x02 58 | #define LCD_ENTRYMODESET 0x04 59 | #define LCD_DISPLAYCONTROL 0x08 60 | #define LCD_CURSORSHIFT 0x10 61 | #define LCD_FUNCTIONSET 0x20 62 | #define LCD_SETCGRAMADDR 0x40 63 | #define LCD_SETDDRAMADDR 0x80 64 | 65 | // flags for display entry mode 66 | #define LCD_ENTRYRIGHT 0x00 67 | #define LCD_ENTRYLEFT 0x02 68 | #define LCD_ENTRYSHIFTINCREMENT 0x01 69 | #define LCD_ENTRYSHIFTDECREMENT 0x00 70 | 71 | // flags for display on/off control 72 | #define LCD_DISPLAYON 0x04 73 | #define LCD_DISPLAYOFF 0x00 74 | #define LCD_CURSORON 0x02 75 | #define LCD_CURSOROFF 0x00 76 | #define LCD_BLINKON 0x01 77 | #define LCD_BLINKOFF 0x00 78 | 79 | // flags for display/cursor shift 80 | #define LCD_DISPLAYMOVE 0x08 81 | #define LCD_CURSORMOVE 0x00 82 | #define LCD_MOVERIGHT 0x04 83 | #define LCD_MOVELEFT 0x00 84 | 85 | // flags for function set 86 | #define LCD_8BITMODE 0x10 87 | #define LCD_4BITMODE 0x00 88 | #define LCD_2LINE 0x08 89 | #define LCD_1LINE 0x00 90 | #define LCD_5x10DOTS 0x04 91 | #define LCD_5x8DOTS 0x00 92 | 93 | class rgb_lcd : public Print { 94 | 95 | public: 96 | rgb_lcd(); 97 | 98 | void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS, TwoWire &wire = Wire); 99 | 100 | void clear(); 101 | void home(); 102 | 103 | void noDisplay(); 104 | void display(); 105 | void noBlink(); 106 | void blink(); 107 | void noCursor(); 108 | void cursor(); 109 | void scrollDisplayLeft(); 110 | void scrollDisplayRight(); 111 | void leftToRight(); 112 | void rightToLeft(); 113 | void autoscroll(); 114 | void noAutoscroll(); 115 | 116 | void createChar(uint8_t, uint8_t[]); 117 | void createCharFromProgmem(uint8_t, const uint8_t *); 118 | void setCursor(uint8_t, uint8_t); 119 | 120 | virtual size_t write(uint8_t); 121 | void command(uint8_t); 122 | 123 | // color control 124 | void setRGB(unsigned char r, unsigned char g, unsigned char b); // set rgb 125 | void setPWM(unsigned char color, unsigned char pwm); // set pwm 126 | 127 | void setColor(unsigned char color); 128 | void setColorAll() { 129 | setRGB(0, 0, 0); 130 | } 131 | void setColorWhite() { 132 | setRGB(255, 255, 255); 133 | } 134 | 135 | // blink the LED backlight 136 | void blinkLED(void); 137 | void noBlinkLED(void); 138 | 139 | using Print::write; 140 | 141 | private: 142 | void send(uint8_t, uint8_t); 143 | void setReg(unsigned char addr, unsigned char dta); 144 | void i2c_send_byte(unsigned char dta); 145 | void i2c_send_byteS(unsigned char* dta, unsigned char len); 146 | 147 | uint8_t rgb_chip_addr; 148 | 149 | uint8_t _displayfunction; 150 | uint8_t _displaycontrol; 151 | uint8_t _displaymode; 152 | 153 | uint8_t _initialized; 154 | 155 | uint8_t _numlines, _currline; 156 | 157 | TwoWire *_wire; 158 | }; 159 | 160 | #endif 161 | -------------------------------------------------------------------------------- /rgb_lcd.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | rgb_lcd.cpp 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 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "rgb_lcd.h" 38 | 39 | void rgb_lcd::i2c_send_byte(unsigned char dta) { 40 | if (!_initialized) { 41 | return; 42 | } 43 | _wire->beginTransmission(LCD_ADDRESS); // transmit to device #4 44 | _wire->write(dta); // sends five bytes 45 | _wire->endTransmission(); // stop transmitting 46 | } 47 | 48 | void rgb_lcd::i2c_send_byteS(unsigned char* dta, unsigned char len) { 49 | if (!_initialized) { 50 | return; 51 | } 52 | _wire->beginTransmission(LCD_ADDRESS); // transmit to device #4 53 | for (int i = 0; i < len; i++) { 54 | _wire->write(dta[i]); 55 | } 56 | _wire->endTransmission(); // stop transmitting 57 | } 58 | 59 | rgb_lcd::rgb_lcd() 60 | : _displayfunction(0), 61 | _displaycontrol(0), 62 | _displaymode(0), 63 | _initialized(0), 64 | _numlines(0), 65 | _currline(0), 66 | _wire(0) 67 | { 68 | } 69 | 70 | void rgb_lcd::begin(uint8_t cols, uint8_t lines, uint8_t dotsize, TwoWire &wire) { 71 | 72 | _wire = &wire; 73 | _wire->begin(); 74 | _initialized = 1; 75 | 76 | if (lines > 1) { 77 | _displayfunction |= LCD_2LINE; 78 | } 79 | _numlines = lines; 80 | _currline = 0; 81 | 82 | // for some 1 line displays you can select a 10 pixel high font 83 | if ((dotsize != 0) && (lines == 1)) { 84 | _displayfunction |= LCD_5x10DOTS; 85 | } 86 | 87 | // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! 88 | // according to datasheet, we need at least 40ms after power rises above 2.7V 89 | // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50 90 | delayMicroseconds(50000); 91 | 92 | 93 | // this is according to the hitachi HD44780 datasheet 94 | // page 45 figure 23 95 | 96 | // Send function set command sequence 97 | command(LCD_FUNCTIONSET | _displayfunction); 98 | delayMicroseconds(4500); // wait more than 4.1ms 99 | 100 | // second try 101 | command(LCD_FUNCTIONSET | _displayfunction); 102 | delayMicroseconds(150); 103 | 104 | // third go 105 | command(LCD_FUNCTIONSET | _displayfunction); 106 | 107 | 108 | // finally, set # lines, font size, etc. 109 | command(LCD_FUNCTIONSET | _displayfunction); 110 | 111 | // turn the display on with no cursor or blinking default 112 | _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; 113 | display(); 114 | 115 | // clear it off 116 | clear(); 117 | 118 | // Initialize to default text direction (for romance languages) 119 | _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT; 120 | // set the entry mode 121 | command(LCD_ENTRYMODESET | _displaymode); 122 | 123 | 124 | // check rgb chip model 125 | _wire->beginTransmission(RGB_ADDRESS_V5); 126 | if (_wire->endTransmission () == 0) 127 | { 128 | rgb_chip_addr = RGB_ADDRESS_V5; 129 | setReg(0x00, 0x07); // reset the chip 130 | delayMicroseconds(200); // wait 200 us to complete 131 | setReg(0x04, 0x15); // set all led always on 132 | } 133 | else 134 | { 135 | rgb_chip_addr = RGB_ADDRESS; 136 | // backlight init 137 | setReg(REG_MODE1, 0); 138 | // set LEDs controllable by both PWM and GRPPWM registers 139 | setReg(REG_OUTPUT, 0xFF); 140 | // set MODE2 values 141 | // 0010 0000 -> 0x20 (DMBLNK to 1, ie blinky mode) 142 | setReg(REG_MODE2, 0x20); 143 | } 144 | 145 | setColorWhite(); 146 | } 147 | 148 | /********** high level commands, for the user! */ 149 | void rgb_lcd::clear() { 150 | command(LCD_CLEARDISPLAY); // clear display, set cursor position to zero 151 | delayMicroseconds(2000); // this command takes a long time! 152 | } 153 | 154 | void rgb_lcd::home() { 155 | command(LCD_RETURNHOME); // set cursor position to zero 156 | delayMicroseconds(2000); // this command takes a long time! 157 | } 158 | 159 | void rgb_lcd::setCursor(uint8_t col, uint8_t row) { 160 | 161 | col = (row == 0 ? col | 0x80 : col | 0xc0); 162 | unsigned char dta[2] = {0x80, col}; 163 | 164 | i2c_send_byteS(dta, 2); 165 | 166 | } 167 | 168 | // Turn the display on/off (quickly) 169 | void rgb_lcd::noDisplay() { 170 | _displaycontrol &= ~LCD_DISPLAYON; 171 | command(LCD_DISPLAYCONTROL | _displaycontrol); 172 | } 173 | 174 | void rgb_lcd::display() { 175 | _displaycontrol |= LCD_DISPLAYON; 176 | command(LCD_DISPLAYCONTROL | _displaycontrol); 177 | } 178 | 179 | // Turns the underline cursor on/off 180 | void rgb_lcd::noCursor() { 181 | _displaycontrol &= ~LCD_CURSORON; 182 | command(LCD_DISPLAYCONTROL | _displaycontrol); 183 | } 184 | 185 | void rgb_lcd::cursor() { 186 | _displaycontrol |= LCD_CURSORON; 187 | command(LCD_DISPLAYCONTROL | _displaycontrol); 188 | } 189 | 190 | // Turn on and off the blinking cursor 191 | void rgb_lcd::noBlink() { 192 | _displaycontrol &= ~LCD_BLINKON; 193 | command(LCD_DISPLAYCONTROL | _displaycontrol); 194 | } 195 | void rgb_lcd::blink() { 196 | _displaycontrol |= LCD_BLINKON; 197 | command(LCD_DISPLAYCONTROL | _displaycontrol); 198 | } 199 | 200 | // These commands scroll the display without changing the RAM 201 | void rgb_lcd::scrollDisplayLeft(void) { 202 | command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVELEFT); 203 | } 204 | void rgb_lcd::scrollDisplayRight(void) { 205 | command(LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT); 206 | } 207 | 208 | // This is for text that flows Left to Right 209 | void rgb_lcd::leftToRight(void) { 210 | _displaymode |= LCD_ENTRYLEFT; 211 | command(LCD_ENTRYMODESET | _displaymode); 212 | } 213 | 214 | // This is for text that flows Right to Left 215 | void rgb_lcd::rightToLeft(void) { 216 | _displaymode &= ~LCD_ENTRYLEFT; 217 | command(LCD_ENTRYMODESET | _displaymode); 218 | } 219 | 220 | // This will 'right justify' text from the cursor 221 | void rgb_lcd::autoscroll(void) { 222 | _displaymode |= LCD_ENTRYSHIFTINCREMENT; 223 | command(LCD_ENTRYMODESET | _displaymode); 224 | } 225 | 226 | // This will 'left justify' text from the cursor 227 | void rgb_lcd::noAutoscroll(void) { 228 | _displaymode &= ~LCD_ENTRYSHIFTINCREMENT; 229 | command(LCD_ENTRYMODESET | _displaymode); 230 | } 231 | 232 | // Allows us to fill the first 8 CGRAM locations 233 | // with custom characters 234 | void rgb_lcd::createChar(uint8_t location, uint8_t charmap[]) { 235 | 236 | location &= 0x7; // we only have 8 locations 0-7 237 | command(LCD_SETCGRAMADDR | (location << 3)); 238 | 239 | 240 | unsigned char dta[9]; 241 | dta[0] = 0x40; 242 | for (int i = 0; i < 8; i++) { 243 | dta[i + 1] = charmap[i]; 244 | } 245 | i2c_send_byteS(dta, 9); 246 | } 247 | 248 | // Equivalent to createChar but using array from PROGMEM 249 | void rgb_lcd::createCharFromProgmem(uint8_t location, const uint8_t *charmap) { 250 | 251 | location &= 0x7; // we only have 8 locations 0-7 252 | command(LCD_SETCGRAMADDR | (location << 3)); 253 | 254 | 255 | unsigned char dta[9]; 256 | dta[0] = 0x40; 257 | for (int i = 0; i < 8; i++) { 258 | dta[i + 1] = pgm_read_byte_near(charmap+i); 259 | } 260 | i2c_send_byteS(dta, 9); 261 | } 262 | 263 | // Control the backlight LED blinking 264 | void rgb_lcd::blinkLED(void) { 265 | if (rgb_chip_addr == RGB_ADDRESS_V5) 266 | { 267 | // attach all led to pwm1 268 | // blink period in seconds = ( + 2) *0.128s 269 | // pwm1 on/off ratio = / 256 270 | setReg(0x04, 0x2a); // 0010 1010 271 | setReg(0x01, 0x06); // blink every second 272 | setReg(0x02, 0x7f); // half on, half off 273 | } 274 | else 275 | { 276 | // blink period in seconds = ( + 1) / 24 277 | // on/off ratio = / 256 278 | setReg(0x07, 0x17); // blink every second 279 | setReg(0x06, 0x7f); // half on, half off 280 | } 281 | 282 | 283 | } 284 | 285 | void rgb_lcd::noBlinkLED(void) { 286 | if (rgb_chip_addr == RGB_ADDRESS_V5) 287 | { 288 | setReg(0x04, 0x15); // 0001 0101 289 | } 290 | else 291 | { 292 | setReg(0x07, 0x00); 293 | setReg(0x06, 0xff); 294 | } 295 | } 296 | 297 | /*********** mid level commands, for sending data/cmds */ 298 | 299 | // send command 300 | inline void rgb_lcd::command(uint8_t value) { 301 | unsigned char dta[2] = {0x80, value}; 302 | i2c_send_byteS(dta, 2); 303 | } 304 | 305 | // send data 306 | inline size_t rgb_lcd::write(uint8_t value) { 307 | 308 | unsigned char dta[2] = {0x40, value}; 309 | i2c_send_byteS(dta, 2); 310 | return 1; // assume sucess 311 | } 312 | 313 | void rgb_lcd::setReg(unsigned char reg, unsigned char dat) { 314 | if (!_initialized) { 315 | return; 316 | } 317 | _wire->beginTransmission(rgb_chip_addr); // transmit to device #4 318 | _wire->write(reg); 319 | _wire->write(dat); 320 | _wire->endTransmission(); // stop transmitting 321 | } 322 | 323 | void rgb_lcd::setRGB(unsigned char r, unsigned char g, unsigned char b) { 324 | if (rgb_chip_addr == RGB_ADDRESS_V5) 325 | { 326 | setReg(0x06, r); 327 | setReg(0x07, g); 328 | setReg(0x08, b); 329 | } 330 | else 331 | { 332 | setReg(0x04, r); 333 | setReg(0x03, g); 334 | setReg(0x02, b); 335 | } 336 | } 337 | 338 | void rgb_lcd::setPWM(unsigned char color, unsigned char pwm) { 339 | switch (color) 340 | { 341 | case WHITE: 342 | setRGB(pwm, pwm, pwm); 343 | break; 344 | case RED: 345 | setRGB(pwm, 0, 0); 346 | break; 347 | case GREEN: 348 | setRGB(0, pwm, 0); 349 | break; 350 | case BLUE: 351 | setRGB(0, 0, pwm); 352 | break; 353 | default: 354 | break; 355 | } 356 | } 357 | 358 | const unsigned char color_define[4][3] = { 359 | {255, 255, 255}, // white 360 | {255, 0, 0}, // red 361 | {0, 255, 0}, // green 362 | {0, 0, 255}, // blue 363 | }; 364 | 365 | void rgb_lcd::setColor(unsigned char color) { 366 | if (color > 3) { 367 | return ; 368 | } 369 | setRGB(color_define[color][0], color_define[color][1], color_define[color][2]); 370 | } 371 | --------------------------------------------------------------------------------