
NUCLEO-L152RE and Arduino LCD 1602......................................For more info see here: http://www.emcu.it/NUCLEOevaBoards/mBed/QSG-Mbed-Library.pdf
main.cpp@1:4ebb3007d683, 2014-05-13 (annotated)
- Committer:
- emcu
- Date:
- Tue May 13 07:01:29 2014 +0000
- Revision:
- 1:4ebb3007d683
- Parent:
- 0:6c0ce5d8252a
Added some comments in the SW.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emcu | 0:6c0ce5d8252a | 1 | |
emcu | 0:6c0ce5d8252a | 2 | // By: www.emcu.it |
emcu | 0:6c0ce5d8252a | 3 | // See also here: http://www.emcu.it/NUCLEOevaBoards/NUCLEOevaBoards.html |
emcu | 1:4ebb3007d683 | 4 | // |
emcu | 0:6c0ce5d8252a | 5 | // Arduino LCD KeyPad Shield |
emcu | 0:6c0ce5d8252a | 6 | // Model: 1602 LCD and 6 AD buttons for Arduino |
emcu | 0:6c0ce5d8252a | 7 | // http://www.robot-italy.com/it/1602-lcd-shield.html |
emcu | 1:4ebb3007d683 | 8 | // |
emcu | 1:4ebb3007d683 | 9 | // |
emcu | 0:6c0ce5d8252a | 10 | /* |
emcu | 0:6c0ce5d8252a | 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
emcu | 0:6c0ce5d8252a | 12 | * of this software and associated documentation files (the "Software"), to deal |
emcu | 0:6c0ce5d8252a | 13 | * in the Software without restriction, including without limitation the rights |
emcu | 0:6c0ce5d8252a | 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
emcu | 0:6c0ce5d8252a | 15 | * copies of the Software, and to permit persons to whom the Software is |
emcu | 0:6c0ce5d8252a | 16 | * furnished to do so, subject to the following conditions: |
emcu | 0:6c0ce5d8252a | 17 | * |
emcu | 0:6c0ce5d8252a | 18 | * The above copyright notice and this permission notice shall be included in |
emcu | 0:6c0ce5d8252a | 19 | * all copies or substantial portions of the Software. |
emcu | 0:6c0ce5d8252a | 20 | * |
emcu | 0:6c0ce5d8252a | 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
emcu | 0:6c0ce5d8252a | 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
emcu | 0:6c0ce5d8252a | 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
emcu | 0:6c0ce5d8252a | 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
emcu | 0:6c0ce5d8252a | 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
emcu | 0:6c0ce5d8252a | 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
emcu | 0:6c0ce5d8252a | 27 | * THE SOFTWARE. |
emcu | 0:6c0ce5d8252a | 28 | */ |
emcu | 0:6c0ce5d8252a | 29 | |
emcu | 0:6c0ce5d8252a | 30 | |
emcu | 0:6c0ce5d8252a | 31 | #include "mbed.h" |
emcu | 0:6c0ce5d8252a | 32 | #include "TextLCD.h" |
emcu | 0:6c0ce5d8252a | 33 | |
emcu | 0:6c0ce5d8252a | 34 | DigitalOut myled(LED1); |
emcu | 0:6c0ce5d8252a | 35 | |
emcu | 0:6c0ce5d8252a | 36 | // |
emcu | 0:6c0ce5d8252a | 37 | // SetUp GPIO for drive the LCD |
emcu | 0:6c0ce5d8252a | 38 | // |
emcu | 0:6c0ce5d8252a | 39 | // LCD (RS, E, D4, D5, D6, D7) |
emcu | 0:6c0ce5d8252a | 40 | TextLCD lcd(PA_9, PC_7, PB_5, PB_4, PB_10, PA_8); // LCD Shield for Arduino |
emcu | 0:6c0ce5d8252a | 41 | AnalogIn button(PA_0); // board button |
emcu | 0:6c0ce5d8252a | 42 | PwmOut backlight(PB_6); |
emcu | 0:6c0ce5d8252a | 43 | |
emcu | 0:6c0ce5d8252a | 44 | |
emcu | 0:6c0ce5d8252a | 45 | /*** |
emcu | 0:6c0ce5d8252a | 46 | * ------------------------------------------------- |
emcu | 0:6c0ce5d8252a | 47 | * Arduino LCD KeyPad Shield |
emcu | 0:6c0ce5d8252a | 48 | * Model: 1602 LCD and 6 AD buttons for Arduino |
emcu | 0:6c0ce5d8252a | 49 | * ------------------------------------------------- |
emcu | 0:6c0ce5d8252a | 50 | * - Button : a0 -> PA0 |
emcu | 0:6c0ce5d8252a | 51 | * right : 0x000 |
emcu | 0:6c0ce5d8252a | 52 | * up : < 0x3ff |
emcu | 0:6c0ce5d8252a | 53 | * down : < 0x7ff |
emcu | 0:6c0ce5d8252a | 54 | * left : < 0xbff |
emcu | 0:6c0ce5d8252a | 55 | * select : 0xfff |
emcu | 0:6c0ce5d8252a | 56 | * --------------------------------------------- |
emcu | 0:6c0ce5d8252a | 57 | * - DB4 : D4 -> PB_5 |
emcu | 0:6c0ce5d8252a | 58 | * - DB5 : D5 -> PB_4 |
emcu | 0:6c0ce5d8252a | 59 | * - DB6 : D6 -> PB_10 |
emcu | 0:6c0ce5d8252a | 60 | * - DB7 : D7 -> PA_8 |
emcu | 0:6c0ce5d8252a | 61 | * - RS : D8 -> PA_9 |
emcu | 0:6c0ce5d8252a | 62 | * - Enable : D9 -> ptd5 |
emcu | 0:6c0ce5d8252a | 63 | * - Backlight Control : D10 -> PB_6 |
emcu | 0:6c0ce5d8252a | 64 | * --------------------------------------------- |
emcu | 0:6c0ce5d8252a | 65 | * - http://www.robot-italy.com/it/1602-lcd-shield.html |
emcu | 0:6c0ce5d8252a | 66 | * |
emcu | 0:6c0ce5d8252a | 67 | ***/ |
emcu | 0:6c0ce5d8252a | 68 | |
emcu | 0:6c0ce5d8252a | 69 | #define ON 1 |
emcu | 0:6c0ce5d8252a | 70 | #define OFF 0 |
emcu | 0:6c0ce5d8252a | 71 | |
emcu | 0:6c0ce5d8252a | 72 | int main() |
emcu | 0:6c0ce5d8252a | 73 | { |
emcu | 0:6c0ce5d8252a | 74 | |
emcu | 0:6c0ce5d8252a | 75 | backlight = ON; // ON: 1, OFF: 0 |
emcu | 0:6c0ce5d8252a | 76 | lcd.cls(); |
emcu | 0:6c0ce5d8252a | 77 | lcd.locate(0,0); |
emcu | 0:6c0ce5d8252a | 78 | lcd.printf("By: www.emcu.it"); |
emcu | 0:6c0ce5d8252a | 79 | wait(2); |
emcu | 0:6c0ce5d8252a | 80 | |
emcu | 0:6c0ce5d8252a | 81 | while (1) |
emcu | 0:6c0ce5d8252a | 82 | { |
emcu | 0:6c0ce5d8252a | 83 | myled = !myled; |
emcu | 0:6c0ce5d8252a | 84 | |
emcu | 0:6c0ce5d8252a | 85 | |
emcu | 0:6c0ce5d8252a | 86 | // READ BUTTON VALUE |
emcu | 0:6c0ce5d8252a | 87 | unsigned long value = button.read_u16(); |
emcu | 0:6c0ce5d8252a | 88 | |
emcu | 0:6c0ce5d8252a | 89 | // LCD OUTPUT |
emcu | 0:6c0ce5d8252a | 90 | lcd.cls(); |
emcu | 0:6c0ce5d8252a | 91 | lcd.locate(0,0); |
emcu | 0:6c0ce5d8252a | 92 | lcd.printf("By: www.emcu.it"); |
emcu | 0:6c0ce5d8252a | 93 | |
emcu | 0:6c0ce5d8252a | 94 | lcd.locate(0,1); |
emcu | 0:6c0ce5d8252a | 95 | lcd.printf("BUTTON : %04x", value); // button value |
emcu | 0:6c0ce5d8252a | 96 | |
emcu | 0:6c0ce5d8252a | 97 | // Test the Push Button on LCD |
emcu | 0:6c0ce5d8252a | 98 | if (value < 0x3ff) // up |
emcu | 0:6c0ce5d8252a | 99 | backlight = ON; |
emcu | 0:6c0ce5d8252a | 100 | else if (value < 0x7ff) // down |
emcu | 0:6c0ce5d8252a | 101 | backlight = OFF; |
emcu | 0:6c0ce5d8252a | 102 | else; |
emcu | 0:6c0ce5d8252a | 103 | wait(0.2); |
emcu | 0:6c0ce5d8252a | 104 | } |
emcu | 0:6c0ce5d8252a | 105 | } |