Hi all!
Overall: I'm trying to make a menu-system with the M2tkLIB with different choices. the User can select different choices and then execute a function.
First off all, I'm a classic noob on an adventure of discovering the secrets of the arduino! So please help me out here =)
The idea is to make a robotic bartender! It means that the user can select a "drink" on the 4x20 LCD-display with the rotary encoder with pushbutton, And my problem here is to make something happen when the user press the button,
How do I implement that I want the "void pumpOJ()" to execute when the user press "Apelsin" (orange juice in swedish). Can you call it a function? I've read the wiki without any progress.
SO basiclly the code is almost like the example besides some small modifications.
#include <LiquidCrystal.h>
#include "M2tk.h"
#include "utility/m2ghlc.h"
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
const int pumpOJpin = 26; //APELSINJUICE , Organge
const int pumpMILKpin = 28; //MJÖLK, MILK
const int pumpSPRITEpin = 30; //SPRITE
const int pumpCBpin = 32; //TRANBÄRSJUICE,
int pumpOJstate = LOW;
int pumpMILKstate = LOW;
int pumpSPRITEstate = LOW;
int pumpCBstate = LOW;
uint8_t uiKeySelectPin = 4;
uint8_t uiKeyNextPin = 3;
uint8_t uiKeyPrevPin = 2; //tillagt
//=================================================
// Forward declaration of the toplevel element
M2_EXTERN_HLIST(menylist);
// Left entry: Menu name. Submenus must have a '.' at the beginning
// Right entry: Reference to the target dialog box (In this example all
//menus call the toplevel element again
m2_menu_entry m2_2lmenu_data[] =
{
{"Woo Woo", NULL },
{"White Russian", },
{"Black Russian", NULL },
{"Sex On The Beach", NULL },
{"Harvey Wallbanger", NULL },
{"Galliano Ice Tea", NULL },
{"AppleOrange Marg.", NULL},
{"Tequila Screwdriv.", &menylist},
{"Fantomen", NULL},
{"Grogg", NULL},
{"Non-Alcoholic", &menylist},
{ ". Apelsin", &menylist},
{ ". Sprite", },
{ ". Tranbaer", },
{ NULL, NULL },
};
// The first visible line and the total number of visible lines.
// Both values are written by M2_2LMENU and read by M2_VSB
uint8_t m2_2lmenu_first;
uint8_t m2_2lmenu_cnt;
// M2_2LMENU definition
// Option l4 = four visible lines
// Option e1 = first column has a width of 1 char
// Option w12 = second column has a width of 12 chars
//M2_LABEL(apa,NULL, "Drinklista: ");
M2_2LMENU(el_2lmenu,"l4e1w16",&m2_2lmenu_first,&m2_2lmenu_cnt, m2_2lmenu_data,'+','-','\0');
M2_VSB(el_vsb, "l3w1r1", &m2_2lmenu_first, &m2_2lmenu_cnt);
M2_LIST(list_2lmenu) = { &el_2lmenu, &el_vsb };
M2_HLIST(menylist, NULL, list_2lmenu);
// m2 object and constructor
M2tk m2(&menylist, m2_es_arduino, m2_eh_4bs, m2_gh_lc);
void setup() {
m2_SetLiquidCrystal(&lcd, 20, 4);
m2.setPin(M2_KEY_SELECT, uiKeySelectPin);
m2.setPin(M2_KEY_NEXT, uiKeyNextPin);
m2.setPin(M2_KEY_PREV, uiKeyPrevPin); //tillagt
pinMode(pumpOJpin, OUTPUT);
pinMode(pumpMILKpin, OUTPUT);
pinMode(pumpSPRITEpin, OUTPUT);
pinMode(pumpCBpin, OUTPUT);
}
void pumpOff() { //Pump OFF
pumpOJstate = LOW;
digitalWrite(pumpOJpin, pumpOJstate);
pumpMILKstate = LOW;
digitalWrite(pumpMILKpin, pumpMILKstate);
pumpSPRITEstate = LOW;
digitalWrite(pumpSPRITEpin, pumpSPRITEstate);
pumpCBstate = LOW;
digitalWrite(pumpCBpin, pumpCBstate);
}
void pumpOJ() { //Pump Orange juice
pumpOJstate = HIGH;
digitalWrite(pumpOJpin, pumpOJstate);
}
void pumpMILK() { //Pump Milk
pumpMILKstate = HIGH;
digitalWrite(pumpMILKpin, pumpMILKstate);
}
void pumpSPRITE() { //Pump Sprite
pumpSPRITEstate = HIGH;
digitalWrite(pumpSPRITEpin, pumpSPRITEstate);
}
void pumpCB() { //Pump Cranberry
pumpCBstate = HIGH;
digitalWrite(pumpCBpin, pumpCBstate);
}
void test(){
pumpOJ();
delay(5000);
pumpOff();
}
void loop() {
m2.checkKey();
m2.checkKey();
if ( m2.handleKey() )
m2.draw();
m2.checkKey();
}