![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
I2C 接続の LCD AQM1602XA-RN-GBW 用のライブラリの使用例. Demo program of library for LCD 1602XA-RN-GBW connected using I2C interface.
Dependencies: mbed UIT_AQM1602
main.cpp@7:3b3317e5f14e, 2016-12-24 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Sat Dec 24 02:36:46 2016 +0000
- Revision:
- 7:3b3317e5f14e
- Parent:
- 6:3dcecef3aa21
- Child:
- 8:ac09e00d2903
8
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 7:3b3317e5f14e | 1 | //---------------------------------------------------------------- |
MikamiUitOpen | 7:3b3317e5f14e | 2 | // Demo program for LCD AQM1602XA-RN-GBW using I2C interface |
MikamiUitOpen | 0:e1b05c7eb023 | 3 | // Pullup resistors for SDA and SCL: 10 kΩ |
MikamiUitOpen | 7:3b3317e5f14e | 4 | // Use mbed Rev.129 for Nucleo-F401/446/746 and DISCO-F746 |
MikamiUitOpen | 7:3b3317e5f14e | 5 | // |
MikamiUitOpen | 7:3b3317e5f14e | 6 | // 2016/12/24, Copyright (c) 2016 MIKAMI, Naoki |
MikamiUitOpen | 7:3b3317e5f14e | 7 | //---------------------------------------------------------------- |
MikamiUitOpen | 0:e1b05c7eb023 | 8 | |
MikamiUitOpen | 0:e1b05c7eb023 | 9 | #include "AQM1602.hpp" |
MikamiUitOpen | 1:6c838e71e330 | 10 | |
MikamiUitOpen | 0:e1b05c7eb023 | 11 | using namespace Mikami; |
MikamiUitOpen | 0:e1b05c7eb023 | 12 | |
MikamiUitOpen | 4:291e82d910d0 | 13 | Aqm1602 lcd_; // Default, OK |
MikamiUitOpen | 4:291e82d910d0 | 14 | //Aqm1602 lcd_(D14, D15); // OK |
MikamiUitOpen | 4:291e82d910d0 | 15 | //Aqm1602 lcd_(D14, D15, 200000); // OK |
MikamiUitOpen | 4:291e82d910d0 | 16 | //Aqm1602 lcd_(D14, D15, 200000, true, true); // OK |
MikamiUitOpen | 4:291e82d910d0 | 17 | //Aqm1602 lcd_(PB_3, PB_10); // OK |
MikamiUitOpen | 4:291e82d910d0 | 18 | //Aqm1602 lcd_(PC_9, PA_8); // OK |
MikamiUitOpen | 4:291e82d910d0 | 19 | //Aqm1602 lcd_(PB_4, PA_8); // OK |
MikamiUitOpen | 4:291e82d910d0 | 20 | //I2C i2cObj_(D14, D15); |
MikamiUitOpen | 4:291e82d910d0 | 21 | //Aqm1602 lcd_(i2cObj_); // OK |
MikamiUitOpen | 4:291e82d910d0 | 22 | |
MikamiUitOpen | 4:291e82d910d0 | 23 | // Following: for LPC1114 |
MikamiUitOpen | 4:291e82d910d0 | 24 | //Aqm1602 lcd_(dp5, dp27); // OK |
MikamiUitOpen | 4:291e82d910d0 | 25 | //I2C i2cObj_(dp5, dp27); |
MikamiUitOpen | 4:291e82d910d0 | 26 | //Aqm1602 lcd_(i2cObj_); // OK |
MikamiUitOpen | 4:291e82d910d0 | 27 | |
MikamiUitOpen | 4:291e82d910d0 | 28 | // Following: for LPC1768 |
MikamiUitOpen | 4:291e82d910d0 | 29 | //Aqm1602 lcd_(p9, p10); // OK |
MikamiUitOpen | 0:e1b05c7eb023 | 30 | |
MikamiUitOpen | 0:e1b05c7eb023 | 31 | Ticker timer_; |
MikamiUitOpen | 7:3b3317e5f14e | 32 | #ifdef STM_USER_BUTTON |
MikamiUitOpen | 0:e1b05c7eb023 | 33 | DigitalIn uButton_(USER_BUTTON); |
MikamiUitOpen | 4:291e82d910d0 | 34 | #endif |
MikamiUitOpen | 0:e1b05c7eb023 | 35 | |
MikamiUitOpen | 0:e1b05c7eb023 | 36 | void TimerIsr() |
MikamiUitOpen | 0:e1b05c7eb023 | 37 | { |
MikamiUitOpen | 0:e1b05c7eb023 | 38 | static int k = 0; |
MikamiUitOpen | 5:d63f1c2d8027 | 39 | lcd_.WriteValueXY("%5.1f", (float)(k++/10.0f), 0, 1); |
MikamiUitOpen | 0:e1b05c7eb023 | 40 | } |
MikamiUitOpen | 0:e1b05c7eb023 | 41 | |
MikamiUitOpen | 0:e1b05c7eb023 | 42 | void WaitButton() |
MikamiUitOpen | 0:e1b05c7eb023 | 43 | { |
MikamiUitOpen | 7:3b3317e5f14e | 44 | #ifdef STM_USER_BUTTON |
MikamiUitOpen | 1:6c838e71e330 | 45 | lcd_.WriteStringXY("Push blue button", 0, 1); |
MikamiUitOpen | 7:3b3317e5f14e | 46 | #ifdef STM32F7 |
MikamiUitOpen | 7:3b3317e5f14e | 47 | while (uButton_ == 0) {} |
MikamiUitOpen | 7:3b3317e5f14e | 48 | #else |
MikamiUitOpen | 0:e1b05c7eb023 | 49 | while (uButton_ == 1) {} |
MikamiUitOpen | 7:3b3317e5f14e | 50 | #endif |
MikamiUitOpen | 4:291e82d910d0 | 51 | #else |
MikamiUitOpen | 5:d63f1c2d8027 | 52 | wait(1); |
MikamiUitOpen | 4:291e82d910d0 | 53 | #endif |
MikamiUitOpen | 1:6c838e71e330 | 54 | lcd_.ClearLine(1); |
MikamiUitOpen | 1:6c838e71e330 | 55 | wait(0.5); |
MikamiUitOpen | 0:e1b05c7eb023 | 56 | } |
MikamiUitOpen | 0:e1b05c7eb023 | 57 | |
MikamiUitOpen | 0:e1b05c7eb023 | 58 | int main() |
MikamiUitOpen | 0:e1b05c7eb023 | 59 | { |
MikamiUitOpen | 6:3dcecef3aa21 | 60 | if (lcd_.IsConnected()) printf("\r\nConnected\r\n"); |
MikamiUitOpen | 6:3dcecef3aa21 | 61 | else printf("\r\nDisconnected\r\n"); |
MikamiUitOpen | 3:fe2f8abf2120 | 62 | |
MikamiUitOpen | 0:e1b05c7eb023 | 63 | lcd_.Clear(); |
MikamiUitOpen | 0:e1b05c7eb023 | 64 | lcd_.WriteString("Hello!"); |
MikamiUitOpen | 0:e1b05c7eb023 | 65 | WaitButton(); // Waiting, push blue user button |
MikamiUitOpen | 0:e1b05c7eb023 | 66 | lcd_.WriteStringXY("0123456789ABCDEF", 0, 0); |
MikamiUitOpen | 0:e1b05c7eb023 | 67 | WaitButton(); // Waiting, push blue user button |
MikamiUitOpen | 0:e1b05c7eb023 | 68 | lcd_.ClearLine(0); |
MikamiUitOpen | 0:e1b05c7eb023 | 69 | WaitButton(); // Waiting, push blue user button |
MikamiUitOpen | 1:6c838e71e330 | 70 | string str = "AQM1602"; |
MikamiUitOpen | 1:6c838e71e330 | 71 | lcd_.WriteStringXY(str+"XA-RN-GBW", 0, 0); |
MikamiUitOpen | 0:e1b05c7eb023 | 72 | TimerIsr(); |
MikamiUitOpen | 5:d63f1c2d8027 | 73 | timer_.attach(&TimerIsr, 0.1f); |
MikamiUitOpen | 0:e1b05c7eb023 | 74 | |
MikamiUitOpen | 0:e1b05c7eb023 | 75 | while (true) {} |
MikamiUitOpen | 0:e1b05c7eb023 | 76 | } |