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:
Sat Jul 30 07:03:01 2016 +0000
Revision:
6:96bc6126d7f0
Parent:
5:4d1ddc9177b0
changed TextLCD_ostream lib for; add to support Akiduki ACM1602NI and NUCLEO-L476RG

Who changed what in which revision?

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