Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ShiftRegLCD.h>
- #include <Buttons.h>
- #define HMENU 4
- #define WMENU 20
- //#define DEBUG 1
- ShiftRegLCD lcd(4, 3, 5, 4);
- #define UPARROW ((uint8_t)3)
- #define DOWNARROW ((uint8_t)4)
- #define SELECT ((uint8_t)5)
- #define HEART ((uint8_t)0)
- #define SMILE ((uint8_t)2)
- #define KEY ((uint8_t)1)
- #define XBEECONF 0
- #define BTCONF 1
- #define CONNCPU 2
- #define CONNGAR 3
- #define CONNSAB 4
- #define BACKMAIN 0
- #define XBEEPPP 1
- #define XBEESM1 2
- #define XBEECLOSE 3
- #define BTPPP 1
- #define BTATR0 2
- #define BTATH 3
- #define BTATF 4
- #define BTATD 5
- #define BTATA 6
- #define BTCLOSE 7
- #define MAINSUB 0
- #define MAINLEN 4 //actual - 1
- const prog_char PROGMEM MenuStr1[] = "XBee Configure";
- const prog_char PROGMEM MenuStr2[] = "BT Configure";
- const prog_char PROGMEM MenuStr3[] = "Connect to CPU";
- const prog_char PROGMEM MenuStr4[] = "Connect to Garden";
- const prog_char PROGMEM MenuStr5[] = "Connect to Sable";
- #define XBEESUB 5 //starts at 2
- #define XBEELEN 3 //actual - 1
- const prog_char PROGMEM Xbee1[] = "Back to Main";
- const prog_char PROGMEM Xbee2[] = "+++";
- const prog_char PROGMEM Xbee3[] = "SM1,ST3e8,SO1";
- const prog_char PROGMEM Xbee4[] = "WN,CN";
- #define BTSUB 9
- #define BTLEN 7 //actual - 1
- const prog_char PROGMEM BTser1[] = "Back to Main";
- const prog_char PROGMEM BTser2[] = "+++ <-not alneeded";
- const prog_char PROGMEM BTser3[] = "ATR0";
- const prog_char PROGMEM BTser4[] = "ATH (drops conn)";
- const prog_char PROGMEM BTser5[] = "ATF?";
- const prog_char PROGMEM BTser6[] = "ATD";
- const prog_char PROGMEM BTser7[] = "ATA";
- const prog_char PROGMEM BTser8[] = "ATO";
- //currentmenu
- #define MAIN MAINSUB
- #define XBEE XBEESUB
- #define BT BTSUB
- PGM_P PROGMEM MenuTable[] = {
- MenuStr1,
- MenuStr2,
- MenuStr3,
- MenuStr4,
- MenuStr5,
- Xbee1,
- Xbee2,
- Xbee3,
- Xbee4,
- BTser1,
- BTser2,
- BTser3,
- BTser4,
- BTser5,
- BTser6,
- BTser7,
- BTser8,
- };
- byte Select[8]={ B01000, B01100, B00110, B11111, B11111, B00110, B01100, B01000};
- char menu = 0; //0 = main
- char menulen = MAINLEN;
- char menusel = 0; //cursor
- char index[20];
- char currmenu = MAIN; //current menu
- void setup()
- {
- lcd.createChar(5, Select);
- for(int i=0; i<20; i++)
- index[i] = i;
- }
- //handle things here, not in loop
- void select(uint8_t cmenu, uint8_t menus)
- {
- switch(cmenu)
- {
- case MAIN:
- if(menus == XBEECONF)
- {
- menu=XBEESUB;
- menulen=XBEELEN;
- currmenu = XBEE;
- }
- else if(menus == BTCONF)
- {
- menu=BTSUB;
- menulen=BTLEN;
- currmenu = BT;
- }
- else
- menu = MAINSUB;
- break;
- case XBEE:
- if(menus == BACKMAIN)
- {
- menu=MAINSUB;
- menulen=MAINLEN;
- currmenu = MAIN;
- }
- else
- menu = XBEESUB;
- break;
- case BT:
- if(menus == BACKMAIN)
- {
- menu=MAINSUB;
- menulen=MAINLEN;
- currmenu = MAIN;
- }
- else
- menu = BTSUB;
- break;
- default:
- break;
- }
- menusel = 0;
- }
- void loop()
- {
- uint8_t button;
- lcd.clear();
- //simple menu here
- for(int i=0; i<HMENU && index[i+menu]-currmenu <= menulen ; i++)
- {
- lcd.setCursor(1,i);
- lcd.print((__FlashStringHelper *)MenuTable[index[i+menu]]);
- }
- //draw select
- lcd.setCursor(0,menusel);
- lcd.write(SELECT);
- #ifdef DEBUG
- lcd.print((char)(menu + '0'));
- lcd.print(' ');
- lcd.print((char)(menusel + '0'));
- #endif
- button = buttonWait(A5,NO,YES);
- if(button == BTND)
- {
- if(index[menu] - currmenu + HMENU-1 < menulen) //space to potentially go down
- menu++;//increment menu
- else if(index[menusel + menu] - currmenu < menulen)
- menusel++;
- else
- {
- //at bottom of menu, go back to top
- menu = currmenu;
- menusel = 0;
- }
- }
- if(button == BTNB)
- select(currmenu, index[menusel+menu]-currmenu);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement