Simblee For Mobile KeyPAD
SFM_KeyPAD
Here is a DEMO creating a KeyPAD.
KeyPAD.ino
KeyPAD.ino
// SimbleeForMobile KeyPAD Example // By ThomasOlson.com // teo20160320.02 // #include
#define SFM SimbleeForMobile #define DEBUG 1 #define MAXVALUESIZE 30 // in bytes void setup() { //override_uart_limit=true; Serial.begin(9600); Serial.println("KeyPAD on Simblee for Mobile\n"); SFM.deviceName = "Simblee"; SFM.advertisementData = "KeyPAD"; SFM.begin(); } void loop() { SFM.process(); }
p3_UI.ino
p3_UI.ino
// Widgets need an ID reference. uint8_t pageHeaderID; uint8_t displayBoxID; uint8_t displayTextID; uint8_t button0ID; uint8_t button1ID; uint8_t button2ID; uint8_t button3ID; uint8_t button4ID; uint8_t button5ID; uint8_t button6ID; uint8_t button7ID; uint8_t button8ID; uint8_t button9ID; //uint8_t buttonStarID; //uint8_t buttonHashID; char numberEntry[MAXVALUESIZE]; // I'm using max 30 char numberic strings uint8_t sendNumberID; uint8_t clearNumberID; void ui() { SFM.beginScreen(); pageHeaderID = SFM.drawText(30,80,"KeyPAD Example"); // Display for KeyPAD displayBoxID = SFM.drawRect(5,115,300,30,GRAY); displayTextID = SFM.drawText(10,120,""); // KeyPAD button1ID = SFM.drawButton(10,150,50,"1"); button2ID = SFM.drawButton(70,150,50,"2"); button3ID = SFM.drawButton(130,150,50,"3"); button4ID = SFM.drawButton(10,200,50,"4"); button5ID = SFM.drawButton(70,200,50,"5"); button6ID = SFM.drawButton(130,200,50,"6"); button7ID = SFM.drawButton(10,250,50,"7"); button8ID = SFM.drawButton(70,250,50,"8"); button9ID = SFM.drawButton(130,250,50,"9"); // buttonStarID = SFM.drawButton(10,300,50,"*",RED); button0ID = SFM.drawButton(70,300,50,"0"); // buttonHashID = SFM.drawButton(130,300,50,"#",RED); clearNumberID = SFM.drawButton(10,350,80,"CLEAR"); sendNumberID = SFM.drawButton(100,350,80,"SEND"); clearValue(); // make sure display value is initially cleared SFM.endScreen(); } void ui_event(event_t &event) { // keyPad decoding if(event.id == button0ID)keyPad("0"); else if(event.id == button1ID)keyPad("1"); else if(event.id == button2ID)keyPad("2"); else if(event.id == button3ID)keyPad("3"); else if(event.id == button4ID)keyPad("4"); else if(event.id == button5ID)keyPad("5"); else if(event.id == button6ID)keyPad("6"); else if(event.id == button7ID)keyPad("7"); else if(event.id == button8ID)keyPad("8"); else if(event.id == button9ID)keyPad("9"); // else if(event.id == buttonStarID)keyPad("*"); // else if(event.id == buttonHashID)keyPad("#"); // other events else if(event.id == sendNumberID) { sendValue(); } else if(event.id == clearNumberID) { clearValue(); } }
p4_callbacks.ino
p4_callbacks.ino
/* * My Callbacks * */ // KeyPad button pressed void keyPad(char *button) { // append current button value to numberEntry string // if there is room in buffer and refresh, else ignore. if(strlen(numberEntry) + strlen(button) < MAXVALUESIZE) { strcat(numberEntry, button); SFM.updateText(displayTextID, numberEntry); } } void clearValue(void) { strcpy(numberEntry,""); SFM.updateText(displayTextID, numberEntry); } void sendValue(void) { Serial.println(numberEntry); clearValue(); }
p5_NOTES.ino
p5_NOTES.ino
/* * * Simulate Keypad - example using Simblee For Mobile * * Each keypad button pressed could be sent to APP. * But in this example I append it to a string waiting * to be CLEARED or SENT to serial port. * * Ultimately a backspace widget would be handy. * */
Download KeyPAD.tar
Other Simblee PROJECTS
Other PROJECTS