0

Please am working on this automatic drink dispenser, i got a sample code as am still an amature. I seem to be stuck and i please need assistance. Components: I2C, keypad, LCD peristaltic pump. Section of code below.

/*This is an open source code gotten from instructables 
and modified by Tolu Olayinka in 2015*/

#include <Wire.h>
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Declaring and to set the LCD I2C address
char keys[] ={'1', '2', '3', 'A', '4', '5', '6', 'B', '7', '8', '9', 'C', '*','0', '#', 'D'}; //"123A456B789C*0#D";

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns

//define the Symbols on the buttons of the keypads
char Keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','O','#','D'}
};
byte rowPins[ROWS] = {0, 2, 3, 4};
byte colPins[COLS] = {5, 6, 7, 8};

int key;
boolean key_lockout=false;
int order[4];
int value=0;

const int vodka=13;   const int whiskey=12;const int water=11; const int coke=10;

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(Keys), rowPins, colPins, ROWS, COLS);

void setup(){
  Serial.begin(9600);
pinMode(vodka, OUTPUT);  pinMode(whiskey, OUTPUT);  pinMode(water, OUTPUT);  pinMode(coke, OUTPUT);
digitalWrite(vodka, HIGH); digitalWrite(whiskey, HIGH);  digitalWrite(water, HIGH);  digitalWrite(coke, HIGH);

  lcd.begin(20,4);
  for(int i = 0; i< 3; i++)  // ------- 3 blinks of backlight  -------------
  {
    lcd.backlight();  delay(250);
    lcd.noBacklight();  delay(250);
  }
  lcd.backlight();
lcd.backlight(); // finish with backlight on 
lcd.clear();
lcd.setCursor(6, 0);
lcd.print("WELCOME");
delay(1000);
lcd.setCursor(1, 2);
lcd.print("My Name is C-BarBa");
lcd.setCursor(0, 3);
lcd.print("A cinoLAB 's project.");
delay (6000);
}


void loop(){
Beginning:
  {
    lcd.clear();
    lcd.setCursor(2,1);
    lcd.print("KEY IN YOUR ORDER");
    delay(5000);
    lcd.setCursor(2,2);
    lcd.print("*-Clear:  #-Enter");
    delay(5000);  

   //I feel the problem starts here...

    char customKey = customKeypad.getKey();

       value=0;
    for (int x=0; x<4; x++){
      char customKey = customKeypad.getKey();  //Get key pressed
      if(customKey ==-1){                      //and here 
        x=x-1;
      }
      else{
        if(customKey != '*' && customKey!='#'){   //If not CLEAR or ENTER
         // value = (10*(value)) + (customKey[key]);
          delay(10);
          lcd.clear();
          lcd.setCursor(0, 1);
          lcd.print("What would you like?");
          delay(10);
          lcd.setCursor(0, 2);
          lcd.print(value);
          delay(500);
        }
        else if(key=='#'){ //If ENTER clicked #exit
          x=4;
        }
        else if (key=='*'){ //If CLEAR clicked #restart
          x=-1;
        }
      }
    }
    lcd.clear();
    lcd.setCursor(0,0); 
    lcd.print("Please Press # to");
    delay(10);
    lcd.setCursor(0,1);
    lcd.print("Confirm drink");
    delay(10);
    lcd.setCursor(14,1);
    lcd.print(value);
    do{
      key=customKeypad.getKey();
    }
    while(key!='*' && key!='#');
    if(key=='*'){
      goto Beginning; //Return to the beginning of loop()
    }
    else if(key=='#'){
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Confirmed");
      delay(1000);
      switch (value) {
      case 1:    
        scotishTea();
        break;
      case 2:    
        jackAndCoke();
        break;
      case 3:    
        vodkaAndCoke();
        break;
      } 
      delay(5);
    }
  }
}
  customKey= customKeypad.getKey(){  //Returns which key is pressed
  int ret=-1;
  boolean reset_lockout=false;
  if(analogRead(A0)<120)
    key_lockout=false;
  else if(!key_lockout){
    delay(100);
    ret=15.5-(log((analogRead(A0)-183.9)/58.24)/0.1623);//+0.5;
    key_lockout=true;
  }
  return ret;
}


//    Menu The part we all have been waiting for
//scotishTea
int scotishTea(){
  digitalWrite(vodka, LOW);
  delay(80);
  digitalWrite(coke, LOW);
  delay(80);
  digitalWrite(water, LOW);
  delay(80);
  //Serial.println("In the matrix");
  digitalWrite(water, HIGH);
  delay(6600);
  digitalWrite(coke, HIGH);
  delay(6400);
  digitalWrite(vodka, HIGH);
  for (int x=0; x<3; x++){
    lcd.clear();
    lcd.setCursor(0,0); //Start at character 4 on line 0
    lcd.print("Add 1oz warm milk");
    delay(10);
    lcd.setCursor(0,1);
    lcd.print(" then MIX");
    delay(5000);
    lcd.clear();
    lcd.print("Add ice and ");
    delay(10);
    lcd.setCursor(0,1);
    lcd.print("top with lime");
    delay(3000);
  }
}

//Jack and Coke
int jackAndCoke(){
  //2 oz of whiskey
  Serial.println("Jack and Coke");
  digitalWrite(coke, LOW);
  delay(10);
  digitalWrite(whiskey, LOW);
  delay(4500);
  digitalWrite(whiskey, HIGH);
  delay(33500);
  digitalWrite(coke, HIGH);
  lcd.clear();
  lcd.setCursor(0,0); //Start at character 4 on line 0
  lcd.print("Add ice and 2-5");
  delay(1000);

}

//vodka and Coke etc 

closed as unclear what you're asking by Nick Gammon Jul 25 '17 at 21:47

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    “seem to be stuck” is a tad too vague. Perhaps indicate kind of problem ... compile error? downloading error? incorrect output or input? Please edit the question and state what it is you do that provokes the problem, then say what the problem is. In telling what the problem is, say what you expect or want to happen and also say what does happen, clearly indicating which is which. – James Waldby - jwpat7 Jun 19 '16 at 4:24
1

You need to be a bit more specific about what your problem is but one thing that I can see us that line where you assign a value tot the variable 'value' is commented out. This way the value entered into the Switch case will always be 0.

if(customKey != '*' && customKey!='#'){   //If not CLEAR or ENTER
     // value = (10*(value)) + (customKey[key]);
      delay(10);

you should remove the '//'

Not the answer you're looking for? Browse other questions tagged or ask your own question.