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)
main.cpp@1:2775f5dc2099, 2016-06-18 (annotated)
- Committer:
- jk1lot
- Date:
- Sat Jun 18 14:20:48 2016 +0000
- Revision:
- 1:2775f5dc2099
- Parent:
- 0:52f56aefba64
- Child:
- 4:0e305f955741
1st published version
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:52f56aefba64 | 6 | TextLCD_I2C_N lcd(&i2c, ST7032_SA, TextLCD::LCD16x2, NC, TextLCD::ST7032_3V3); |
jk1lot | 0:52f56aefba64 | 7 | lcd_ostream lcds(&lcd); |
jk1lot | 0:52f56aefba64 | 8 | |
jk1lot | 0:52f56aefba64 | 9 | int main() { |
jk1lot | 0:52f56aefba64 | 10 | using namespace std; |
jk1lot | 0:52f56aefba64 | 11 | lcd.setContrast(32); |
jk1lot | 0:52f56aefba64 | 12 | while(true) { |
jk1lot | 1:2775f5dc2099 | 13 | // lcds.cls() は lcd_ostream& を返すので、そこにそのまま << 出来る |
jk1lot | 1:2775f5dc2099 | 14 | // endl で次の行の先頭に行く |
jk1lot | 1:2775f5dc2099 | 15 | lcds.cls() << "Hello world" << endl << "LCD ostream"; |
jk1lot | 1:2775f5dc2099 | 16 | wait(2); |
jk1lot | 1:2775f5dc2099 | 17 | lcds.cls(); |
jk1lot | 1:2775f5dc2099 | 18 | for(int i=0; i<6; i++) { |
jk1lot | 1:2775f5dc2099 | 19 | //最下行で endl すると1行目に移動する |
jk1lot | 1:2775f5dc2099 | 20 | lcds << "line:" << i << endl; |
jk1lot | 1:2775f5dc2099 | 21 | wait(1); |
jk1lot | 1:2775f5dc2099 | 22 | } |
jk1lot | 1:2775f5dc2099 | 23 | lcds.cls() << 10L << ',' << setw(4) << 3.14f << endl << "count: "; |
jk1lot | 0:52f56aefba64 | 24 | for(int i=3; i>=0; i--) { |
jk1lot | 1:2775f5dc2099 | 25 | // locate() も cls()と同様に続けて << 出来る |
jk1lot | 0:52f56aefba64 | 26 | lcds.locate(8,1) << i; |
jk1lot | 0:52f56aefba64 | 27 | wait(1); |
jk1lot | 0:52f56aefba64 | 28 | } |
jk1lot | 1:2775f5dc2099 | 29 | wait(2); |
jk1lot | 0:52f56aefba64 | 30 | } |
jk1lot | 0:52f56aefba64 | 31 | } |