sample program using TextLCD_ostream

Dependencies:   TextLCD_ostream mbed

This is sample program using std::ostream with TextLCD
Because a large amount of memory is needed, it does not work in low memory MPU.
(It works fine on mbed LPC1768 and STM32 Nucleo-L476RG. But linker error occard on TG-LPC11U35-501)

Committer:
jk1lot
Date:
Sun Jun 26 08:36:08 2016 +0000
Revision:
5:4d1ddc9177b0
Parent:
4:0e305f955741
Child:
6:96bc6126d7f0
add exsample of I2C TextLCD which Easily available at Japan

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jk1lot 0:52f56aefba64 1 #include "mbed.h"
jk1lot 0:52f56aefba64 2 #include "TextLCD_ostream.h"
jk1lot 1:2775f5dc2099 3 #include <iomanip>
jk1lot 0:52f56aefba64 4
jk1lot 0:52f56aefba64 5 I2C i2c(p28,p27); // SDA, SCL
jk1lot 5:4d1ddc9177b0 6
jk1lot 5:4d1ddc9177b0 7 //マルツ MI2CLCD-01 I2C 16x2+icon
jk1lot 5:4d1ddc9177b0 8 //ストロベリーリナックス I2C 16x2+icon
jk1lot 5:4d1ddc9177b0 9 //秋月 小型I2C 16x2
jk1lot 5:4d1ddc9177b0 10 TextLCD_I2C_N lcd(&i2c);
jk1lot 5:4d1ddc9177b0 11 const int LCDCONTRAST=32;
jk1lot 5:4d1ddc9177b0 12
jk1lot 5:4d1ddc9177b0 13 //秋月 超小型I2C 8x2
jk1lot 4:0e305f955741 14 //TextLCD_I2C_N lcd(&i2c, ST7032_SA, TextLCD::LCD8x2);
jk1lot 4:0e305f955741 15 //const int LCDCONTRAST=20;
jk1lot 5:4d1ddc9177b0 16 //秋月 PIC搭載 I2C 16x2 これはうまくいかない
jk1lot 5:4d1ddc9177b0 17 //TextLCD_I2C_N lcd(&i2c, 0xA0, TextLCD::LCD16x2,NC,TextLCD::ST7066_ACM);
jk1lot 5:4d1ddc9177b0 18 //const int LCDCONTRAST=0; //contrast control is not supported
jk1lot 4:0e305f955741 19
jk1lot 0:52f56aefba64 20 lcd_ostream lcds(&lcd);
jk1lot 0:52f56aefba64 21
jk1lot 0:52f56aefba64 22 int main() {
jk1lot 0:52f56aefba64 23 using namespace std;
jk1lot 5:4d1ddc9177b0 24 // lcds.lcd() で元の TextLCDにアクセス出来る
jk1lot 5:4d1ddc9177b0 25 if(LCDCONTRAST) lcds.lcd().setContrast(LCDCONTRAST);
jk1lot 0:52f56aefba64 26 while(true) {
jk1lot 1:2775f5dc2099 27 // lcds.cls() は lcd_ostream& を返すので、そこにそのまま << 出来る
jk1lot 1:2775f5dc2099 28 // endl で次の行の先頭に行く
jk1lot 1:2775f5dc2099 29 lcds.cls() << "Hello world" << endl << "LCD ostream";
jk1lot 1:2775f5dc2099 30 wait(2);
jk1lot 1:2775f5dc2099 31 lcds.cls();
jk1lot 1:2775f5dc2099 32 for(int i=0; i<6; i++) {
jk1lot 1:2775f5dc2099 33 //最下行で endl すると1行目に移動する
jk1lot 1:2775f5dc2099 34 lcds << "line:" << i << endl;
jk1lot 1:2775f5dc2099 35 wait(1);
jk1lot 1:2775f5dc2099 36 }
jk1lot 1:2775f5dc2099 37 lcds.cls() << 10L << ',' << setw(4) << 3.14f << endl << "count: ";
jk1lot 0:52f56aefba64 38 for(int i=3; i>=0; i--) {
jk1lot 1:2775f5dc2099 39 // locate() も cls()と同様に続けて << 出来る
jk1lot 0:52f56aefba64 40 lcds.locate(8,1) << i;
jk1lot 0:52f56aefba64 41 wait(1);
jk1lot 0:52f56aefba64 42 }
jk1lot 1:2775f5dc2099 43 wait(2);
jk1lot 0:52f56aefba64 44 }
jk1lot 0:52f56aefba64 45 }