Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Antonio Villanueva Rotation du texte avec réinsertion
- LCD i2c test https://github.com/johnrickman/LiquidCrystal_I2C
- */
- //LCD config
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- #define cols 16
- #define lignes 2
- LiquidCrystal_I2C lcd(0x27,cols ,lignes); // Address i2c 0x27 0x3f
- /***************************************************************************************************/
- /***************************************************************************************************/
- //variables
- unsigned int x(0),y(0);
- String message("Tony Villanueva");
- String message2("Segura");
- /***************************************************************************************************/
- void printMessage(String &msg,unsigned int &x , unsigned int y);//imprime un message dans une position x,y
- void error(String msg="E R R O R");//Message error limites afficheur
- /***************************************************************************************************/
- /***************************************************************************************************/
- void setup() {
- // void begin(uint8_t cols, uint8_t rows, uint8_t charsize = LCD_5x8DOTS );
- lcd.init();
- lcd.backlight();//lcd.noBacklight();
- //lcd.cursor_on();
- //lcd.blink_on();
- }
- /***************************************************************************************************/
- void loop() {
- scrollLineRight(message,x,y);
- scrollLineRight(message2,x,1);
- //lcd.scrollDisplayRight();
- delay (500);
- }
- /***************************************************************************************************/
- void scrollLineRight(String &msg,unsigned int &x,unsigned int y){
- //Rotation une ligne
- String tmp("");
- for (int i=0;i<x;i++){tmp=' ';}//Cree space au debut
- tmp+=msg;//Colle le message
- for (int i= 16-(tmp.length ()+x) ; i>0;i--){ tmp+=' ';}//Cree space à la fin
- msg=tmp.charAt(15);//dernier caractère à la première position
- msg+=tmp.substring(0,15);
- printMessage(msg,0,y);
- }
- /***************************************************************************************************/
- void printMessage(String msg,unsigned int x , unsigned int y){//imprime un message dans une position x,y
- if (limits(x,y,msg)){
- error( "x="+String(x)+" ,y="+String(y)+",txt="+String(msg.length()));
- return;
- }
- //lcd.clear();
- lcd.setCursor(x,y);
- lcd.print(msg);
- }
- /***************************************************************************************************/
- bool limits(unsigned int x,unsigned int y,String msg){//Test limits ecran xy
- if ( (x+msg.length())>16 || y>1){return true;}
- return false;
- }
- /***************************************************************************************************/
- void error(String msg="E R R O R"){//Message error limites afficheur
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print(msg);
- }
- /***************************************************************************************************/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement