Demo of the RA8875 Keypad to enter a username and password.
Dependencies: mbed RA8875 Keypad
Diff: main.cpp
- Revision:
- 4:8c1932fcd628
- Parent:
- 3:954431ea9b0d
--- a/main.cpp Sat Mar 05 16:50:26 2016 +0000 +++ b/main.cpp Sat Aug 06 20:08:58 2016 +0000 @@ -1,13 +1,31 @@ -#include "mbed.h" // v112 -#include "RA8875.h" -#include "Keypad.h" +#include "mbed.h" // v122 +#include "RA8875.h" // v127 +#include "Keypad.h" // v4 + +// These two defines can be enabled, or commented out +#define BIG_SCREEN +#define CAP_TOUCH +#define LCD_C 16 // color - bits per pixel -LocalFileSystem local("local"); // Because I want <PrintScreen> +#ifdef CAP_TOUCH +RA8875 lcd(p5, p6, p7, p12, NC, p9,p10,p13, "tft"); // MOSI,MISO,SCK,/ChipSelect,/reset, SDA,SCL,/IRQ, name +#else +RA8875 lcd(p5, p6, p7, p12, NC, "tft"); //MOSI, MISO, SCK, /ChipSelect, /reset, name +LocalFileSystem local("local"); // access to calibration file for resistive touch. +#endif + +#ifdef BIG_SCREEN + #define LCD_W 800 + #define LCD_H 480 +#else + #define LCD_W 480 + #define LCD_H 272 +#endif + Serial pc(USBTX, USBRX); // And a little feedback - -RA8875 lcd(p5, p6, p7, p12, NC, "tft"); // MOSI, MISO, SCK, /ChipSelect, /reset, name Keypad kp(lcd); +// Define a keyboard layout as a calculator-like keypad // 789 /( // 456 *) // 123 - @@ -20,6 +38,7 @@ 0,0 }; +// Define the implementation of that keyboard const Keypad::keyboard_t altkeyboard = { 100, // x=100; left edge 0, // y=0; computed from bottom up @@ -78,6 +97,7 @@ char name2[20]; kp.SetKeyboard(); + kp.SetKeyboardFont(0, 2); // big characters lcd.puts(0,20, "Enter username and password\r\n"); if (kp.GetString(name1, sizeof(name1), "Username:")) { //lcd.printf("username: %s\r\n", name1); @@ -93,7 +113,7 @@ lcd.SetTextFontSize(); } } else { - kp.Erase(); + //kp.Erase(); pc.printf("<esc>\r\n"); } } @@ -102,7 +122,8 @@ void CalculatorKeypadTest(void) { char name1[20]; - kp.SetKeyboard(&altkeyboard, '='); + kp.SetKeyboard(&altkeyboard, '=', 0); + kp.SetKeyboardFont(0, 4); if (kp.GetString(name1, sizeof(name1), "Calc:")) { lcd.foreground(BrightRed); lcd.background(Black); @@ -124,6 +145,7 @@ // now select this tiny keyboard kp.SetKeyboard(&tiny); + kp.SetKeyboardFont(0, 1); if (kp.GetString(name1, sizeof(name1), "Cprs:")) { lcd.foreground(BrightRed); lcd.background(Black); @@ -138,13 +160,17 @@ int main() { - int testNum = 2; // starting test + int testNum = 0; // starting test pc.baud(460800); // I like a snappy terminal, so crank it up! pc.printf("\r\nDev Keypad - Build " __DATE__ " " __TIME__ "\r\n"); - lcd.init(); + lcd.init(LCD_W, LCD_H, LCD_C); + lcd.Backlight(0.5f); + + #ifndef CAP_TOUCH InitTS(); + #endif while(1) { lcd.foreground(Yellow); lcd.background(Black);