NUCLEO-L152RE and Arduino LCD 1602......................................For more info see here: http://www.emcu.it/NUCLEOevaBoards/mBed/QSG-Mbed-Library.pdf

Dependencies:   mbed

Committer:
emcu
Date:
Sun May 11 07:13:01 2014 +0000
Revision:
0:6c0ce5d8252a
Child:
1:4ebb3007d683
NUCLEO-L152RE and Arduino LCD 1602

Who changed what in which revision?

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