Mbed for ESIMEos / Mbed 2 deprecated FRDM-KL46Z_LCD_I2C_demo

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /************************************************
00002  * This example code is in the public domain.
00003  * @file    LCD_I2C.ino
00004  * @brief   Demonstrates use of the LCD Library
00005  * @author  Nicolas BOUTIN
00006  * @date    31/05/2013
00007  * 
00008  * Board    Arduino UNO R3
00009  * IDE      Atmel Studio 6.1
00010  * LCD I2C  PCM2004E6-2
00011  * Pin      Board   LCD
00012  *          SDA_20  SDA (blanc) + resistance pull-up 2k
00013  *          SCL_21  SCL (jaune) + resistance pull-up 2k
00014  *          5V      5V (rouge
00015  *          GND     GND (noir)
00016  ***********************************************/
00017 
00018 /************************************************
00019  * INCLUDE
00020  ***********************************************/
00021 #include "mbed.h"
00022 #include "WireKinetis.h"
00023 #include "Printable.h"
00024 
00025 #include "LiquidCrystal_I2C.h"
00026 
00027 /**
00028  * The Streaming library must be included in order to use "operator<<"         
00029  * It can be find at the following address :
00030  * http://arduiniana.org/libraries/streaming/
00031  * I am not the author of it but it is a must-have
00032  */
00033 #include "Streaming.h"
00034 
00035 /*****************************************************************************
00036  * CLASS Printable
00037  *****************************************************************************/
00038 class PrintableObject : public Printable
00039 {
00040     private:
00041     uint8_t ui8_val;
00042     String my_name;
00043 
00044     public:
00045     PrintableObject(uint8_t val, String name)
00046     {
00047         ui8_val = val;
00048         my_name = name;
00049     }
00050     
00051     virtual size_t printTo(Print& p) const
00052     {
00053         p << "My name is " << my_name << endl;
00054         p << "Value :" << ui8_val << endl;
00055     }
00056 };
00057 
00058 /*****************************************************************************
00059  * Object instantiation
00060  *****************************************************************************/
00061 LCD_I2C lcd(0x00, 4, 20);
00062 
00063 /*****************************************************************************
00064  * Setup
00065  *****************************************************************************/
00066 void setup()
00067 {
00068     lcd.begin();
00069 }
00070 
00071 /*****************************************************************************
00072  * Main Loop
00073  *****************************************************************************/
00074 void loop()
00075 {
00076     static uint32_t cnt_loop = 0;
00077     cnt_loop++;
00078     
00079     uint32_t ui32_lcd_delay = 3000;
00080     
00081     uint8_t uc_val = 0xFF;
00082     int32_t i32_val = -456798;
00083     uint32_t ui32_val = 0xFFFFFFFF;
00084     float f_val = 1234.89;
00085 
00086     lcd.clear();
00087     lcd << "-- Operator << --" << endl;
00088     delay(ui32_lcd_delay);
00089 
00090     lcd.clear();
00091     lcd.println(F("Const char in flash"));
00092     lcd.println(F("I am in flash !"));
00093     delay(ui32_lcd_delay);
00094     
00095     lcd.clear();
00096     lcd.println(F("-- Print String --"));
00097     String string("I am a string !");
00098     lcd << string << endl;
00099     delay(ui32_lcd_delay);
00100     
00101     lcd.clear();
00102     lcd << "-- Print char --" << endl;
00103     lcd << "char : " << 'a' << endl;
00104     delay(ui32_lcd_delay);
00105     
00106     lcd.clear();
00107     lcd << "-- Print Printable --" << endl;
00108     PrintableObject my_object(15, "my object");
00109     lcd << my_object << endl;
00110     delay(ui32_lcd_delay);
00111 
00112     lcd.clear();
00113     lcd << "-- Print number --" << endl;
00114     lcd << "uint8_t: " << uc_val << endl;
00115     lcd << "uint8_t: 0x" << _HEX(uc_val) << endl;
00116     lcd << "uint8_t: 0b" << _BIN(uc_val) << endl;
00117     delay(ui32_lcd_delay);
00118 
00119     lcd.clear();
00120     lcd << "-- Print number --" << endl;
00121     lcd << "int32_t: " << i32_val << endl;
00122     lcd << "int32_t: 0x" << _HEX(i32_val) << endl;
00123     delay(ui32_lcd_delay);
00124 
00125     lcd.clear();
00126     lcd << "-- Print float --" << endl;
00127     lcd << "float: " << f_val << endl;
00128     delay(ui32_lcd_delay);
00129     
00130     lcd.clear();
00131     lcd << "-- Backlight OFF --" << endl;
00132     lcd.backlight(false);
00133     delay(ui32_lcd_delay);
00134 
00135     lcd.clear();
00136     lcd << "-- Backlight ON --" << endl;
00137     lcd.backlight(true);
00138     delay(ui32_lcd_delay);
00139 
00140     lcd.clear();
00141     lcd << "-- CursorXY (5,3) --" << endl;
00142     lcd.cursorXY(5, 3);
00143     lcd << 'X';
00144     delay(ui32_lcd_delay);
00145 
00146     lcd.clear();
00147     lcd << "- CursorXY (10,2) -" << endl;
00148     lcd << _XY(10, 2) << 'X';
00149     delay(ui32_lcd_delay);
00150     
00151     lcd.clear();
00152     lcd.print("-- Cursor OFF --");
00153     lcd.cursor(false);
00154     delay(ui32_lcd_delay);
00155 
00156     lcd.clear();
00157     lcd.print("-- Cursor ON --");
00158     lcd.cursor(true);
00159     delay(ui32_lcd_delay);
00160 
00161     lcd.clear();
00162     lcd << "-- Cursor Home --" << endl;
00163     lcd.home();
00164     delay(ui32_lcd_delay);
00165     
00166     lcd.clear();
00167     lcd.cursor(false);
00168     
00169     for(uint8_t j = 0; j < 4; j++)
00170     {
00171         uint8_t i = 0;
00172         for (i = 0; i < 13; i++) //move string to right
00173         {
00174             lcd.cursorXY(i, 1);
00175             lcd << " Hello ";
00176             delay(100); //delay 100ms
00177         }
00178         for (; i > 0; i--) //move string to left
00179         {
00180             lcd.cursorXY(i, 1);
00181             lcd << " Hello ";
00182             delay(100);
00183         }
00184     }
00185     
00186     lcd.clear();
00187     lcd << _XY(1,0) << "Thanks for watching" << endl;
00188     delay(10000);
00189 }
00190 
00191 /*****************************************************************************
00192  * END OF FILE
00193  *****************************************************************************/