Using 4x4 Key Pad to enter Varaible

Hi I’m New to Arduino, trying to Make Check Weigher - where User can input weight Limit by 4x4 Keypad. Can enter the variable values by Keypad but main_process loop is not running continuously to get the real time measured weight …pleae help. Below is the code I’m using

#include <Wire.h>
#include <LiquidCrystal.h>
#include <LCDKeypad.h>
#include “HX711.h”
#include <Keypad.h>

LCDKeypad lcd;

const byte ROWS = 4;
const byte COLS = 4;

char keys [ROWS] [COLS] = {
{‘1’, ‘2’, ‘3’, ‘A’},
{‘4’, ‘5’, ‘6’, ‘B’},
{‘7’, ‘8’, ‘9’, ‘C’},
{’*’, ‘0’, ‘#’, ‘D’}
};

byte rowPins [ROWS] = {22, 24, 26, 28};
byte colPins [COLS] = {30, 32, 34, 36};

Keypad kpd = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

int Wt1;
int Wt2;
int Wt3;

int count=0;
int i=0;
int weight; // weight actual

int relay1 = 11;
int relay2 = 12;
int buzzer = 13;

int process;
int gnd = A1;
int vcc = A4;
float callibaration = 1.2;

HX711 scale(A2, A3);//(DOUT, SCK);

void setup() {

pinMode(gnd, OUTPUT); analogWrite(gnd, 0);
pinMode(vcc, OUTPUT); analogWrite(vcc, 254);
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(buzzer, OUTPUT);

digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
digitalWrite(buzzer, LOW);

delay(1000);

digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
digitalWrite(buzzer, HIGH);

lcd.begin(16, 2);
lcd.clear();
lcd.setCursor (0, 0);
lcd.print(“Check Weigher”);
lcd.setCursor (0, 1);
lcd.print(“By SSinha”);
delay(3000);
lcd.clear();
lcd.print(“WARNING”);
lcd.setCursor (0, 1);
lcd.print(“Max Cap. 5Kg”);
delay(3000);
scale.set_scale();
scale.set_scale(-252.f);
scale.tare();
process = 1;
lcd.clear();
lcd.print(“Input ABC #=Entr”);
lcd.setCursor (0, 1);
lcd.print(“D = Disp/Start”);

}

void main_process () {
lcd.clear();
lcd.setCursor (0, 0);
lcd.print(“Empt Full Max.”);
lcd.setCursor (0, 1);
lcd.print (Wt1);
lcd.setCursor (6, 1);
lcd.print (Wt2);
lcd.setCursor (12, 1);
lcd.print (Wt3);
delay(3000);
lcd.clear();
scale.power_down();
delay(500);
scale.power_up();
int b = (scale.get_units());
lcd.clear();
lcd.setCursor (0, 0);
weight = b * callibaration;
if (weight <= 0) weight = 0;
lcd.print(weight);
lcd.print(" gram");

if (weight >= Wt1){
digitalWrite(relay1, LOW);
}else digitalWrite(relay1, HIGH);

if (weight >= Wt2){
digitalWrite(relay2, LOW);
digitalWrite(relay1, HIGH);
} else digitalWrite(relay2, HIGH);

if (weight >= Wt3){
digitalWrite(relay2, HIGH);
digitalWrite(buzzer, LOW);
}else digitalWrite(buzzer, HIGH);

process = 1;
}

void loop1()
{
Wt1 = GetNumber();
Wt2 = GetNumber();
Wt3 = GetNumber();
}

void set_Wt1 () { // relay 1
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Empty Crtn Wt.”);
lcd.setCursor(0, 1);
Wt1 = GetNumber();
lcd.clear();
lcd.print(Wt1);
lcd.print(" gram");
}

void set_Wt2 () { // relay 2
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Full Crtn Wt.”);
lcd.setCursor(0, 1);
Wt2= GetNumber();
lcd.clear();
lcd.print(Wt2);
lcd.print(" gram");
}

void set_Wt3 () { // buzzer
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Maximum Wt.”);
lcd.setCursor(0, 1);
Wt3 = GetNumber();
lcd.clear();
lcd.print(Wt3);
lcd.print(" gram");
}

int GetNumber()
{
int num = 0;
char key = kpd.getKey();
while(key != ‘#’)
{
switch (key)
{
case NO_KEY:
break;

case ‘0’: case ‘1’: case ‘2’: case ‘3’: case ‘4’:
case ‘5’: case ‘6’: case ‘7’: case ‘8’: case ‘9’:
lcd.print(key);
num = num * 10 + (key - ‘0’);
break;

case ‘A’:
set_Wt1 ();
case ‘B’:
set_Wt2 ();
case ‘C’:
set_Wt3 ();
case ‘D’:
break;

}

key = kpd.getKey();

}

return num;

}

void loop() {
loop1 ();
void main_process ();

}

  1. please put your code into the tag code, by midifying your post.
  2. please cancel the “void” in the loop {}, near main_process
#include <Wire.h>



#include <LiquidCrystal.h>



#include <LCDKeypad.h>



#include "HX711.h"



#include <Keypad.h> 



 



LCDKeypad lcd;



 



const byte ROWS = 4; 



const byte COLS = 4;



 



  char keys [ROWS]
[COLS] = { 



  {'1', '2', '3',
'A'},



  {'4', '5', '6',
'B'},



  {'7', '8', '9',
'C'},



  {'*', '0', '#', 'D'}



};



 



byte rowPins [ROWS] = {22, 24, 26, 28}; 



byte colPins [COLS] = {30, 32, 34, 36};



 



Keypad kpd = Keypad(makeKeymap(keys), rowPins, colPins,
ROWS, COLS);



 



int Wt1;



int Wt2;



int Wt3;



 



int count=0;



int i=0;



int weight; // weight actual



 



int relay1 = 11;



int relay2 = 12;



int buzzer = 13;



 



int process;



int gnd = A1;



int vcc = A4;



float callibaration = 1.2;



 



HX711 scale(A2, A3);//(DOUT, SCK);



 



void setup() {



 



  pinMode(gnd,
OUTPUT); analogWrite(gnd, 0);



  pinMode(vcc,
OUTPUT); analogWrite(vcc, 254);



  pinMode(relay1,
OUTPUT);



  pinMode(relay2,
OUTPUT);



  pinMode(buzzer,
OUTPUT);



    



 digitalWrite(relay1,
LOW);



 digitalWrite(relay2,
LOW);



 digitalWrite(buzzer,
LOW);



    



  delay(1000); 



  



 digitalWrite(relay1,
HIGH);



 digitalWrite(relay2,
HIGH);



 digitalWrite(buzzer,
HIGH);



    



  



  lcd.begin(16, 2);



  lcd.clear();



  lcd.setCursor (0,
0);



 
lcd.print("Check Weigher");



  lcd.setCursor (0,
1);



  lcd.print("By
SSiha");



  delay(3000);



  lcd.clear();



  lcd.print("WARNING");



  lcd.setCursor (0,
1);



  lcd.print("Max
Cap. 5Kg");



  delay(3000);



  scale.set_scale(); 



 
scale.set_scale(-252.f);



  scale.tare();



  process = 1;



  lcd.clear();



 
lcd.print("Input ABC #=Entr");



  lcd.setCursor (0,
1);



  lcd.print("D =
Disp/Start");



  



      



}



 



void main_process () {



  lcd.clear();



  lcd.setCursor (0,
0);



 
lcd.print("Empt  Full  Max.");



  lcd.setCursor (0,
1);



  lcd.print (Wt1);



  lcd.setCursor (6,
1);



  lcd.print (Wt2);



  lcd.setCursor (12,
1);



  lcd.print (Wt3);



  delay(3000);



  lcd.clear();



  scale.power_down();



  delay(500);



  scale.power_up();



  int b =
(scale.get_units());



  lcd.clear();



  lcd.setCursor (0,
0);



  weight = b *
callibaration;



  if (weight <= 0)
weight = 0;



  lcd.print(weight);



  lcd.print("
gram");



 



  if (weight >=
Wt1){



   
digitalWrite(relay1, LOW);



  }else
digitalWrite(relay1, HIGH);



 



  if (weight >=
Wt2){



   
digitalWrite(relay2, LOW);



   
digitalWrite(relay1, HIGH);



  } else
digitalWrite(relay2, HIGH);



 



 



  if (weight >=
Wt3){



      digitalWrite(relay2,
HIGH); 



   
digitalWrite(buzzer, LOW);



  }else
digitalWrite(buzzer, HIGH);



 



  process = 1;



}



 



void loop1() 



{  



  Wt1 = GetNumber();



  Wt2 = GetNumber();



  Wt3 = GetNumber(); 



}



 



 



void  set_Wt1 () { //
relay 1



  lcd.clear();



  lcd.setCursor(0, 0);



 
lcd.print("Empty Crtn Wt.");



  lcd.setCursor(0, 1);



  Wt1 = GetNumber();



  lcd.clear();



  lcd.print(Wt1);



  lcd.print("
gram");



}



 



void  set_Wt2 () { //
relay 2



  lcd.clear();



  lcd.setCursor(0, 0);



  lcd.print("Full
Crtn Wt.");



  lcd.setCursor(0, 1);



  Wt2= GetNumber();



  lcd.clear();



  lcd.print(Wt2);



  lcd.print("
gram");



}



 



void  set_Wt3 () { //
buzzer



  lcd.clear();



  lcd.setCursor(0, 0);



 
lcd.print("Maximum Wt.");



  lcd.setCursor(0, 1);



  Wt3   = GetNumber();



  lcd.clear();



  lcd.print(Wt3);



  lcd.print("
gram");



}



 



 



 



 



int GetNumber()



{



   int num = 0;



   char key =
kpd.getKey();



   while(key != '#')



   {



      switch (key)



      {



         case NO_KEY:



            break;



 



         case '0':
case '1': case '2': case '3': case '4':



         case '5':
case '6': case '7': case '8': case '9':



           
lcd.print(key);



            num = num
* 10 + (key - '0');



            break;



 



      case 'A':



      set_Wt1 ();



      case 'B':



      set_Wt2 ();



      case 'C':



      set_Wt3 ();



      case 'D':



      break;



      



      }



 



      key =
kpd.getKey();



      



   }



 



   return num;



   



}



 



 



 



 loop() {



 loop1 (); 



 void main_process ();



  



}

Thanks Silente for the response, attached is the code file, removing “void” from loop - will try and revert.
Thanks again

help1.ino (3.61 KB)

Hi Silente, I tried removing "void" near main_process, but it resulted in compiling error --> "expected constrctor, destructor or type of conversion before ',' token"

Try removing “void” from before “main_process”, not from before “loop”.

Also, in the future, please copy and paste a complete error message, rather than mis-typing part of the error message.

The sketch is easier to read without the extra 650 line breaks:

#include <Wire.h>
#include <LiquidCrystal.h>
#include <LCDKeypad.h>
#include "HX711.h"
#include <Keypad.h>


LCDKeypad lcd;


const byte ROWS = 4;
const byte COLS = 4;


char keys [ROWS][COLS] =
{
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};


byte rowPins [ROWS] = {22, 24, 26, 28};
byte colPins [COLS] = {30, 32, 34, 36};


Keypad kpd = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);


int Wt1;
int Wt2;
int Wt3;


int count = 0;
int i = 0;
int weight; // weight actual


int relay1 = 11;
int relay2 = 12;
int buzzer = 13;


int process;
int gnd = A1;
int vcc = A4;
float callibaration = 1.2;


HX711 scale(A2, A3);//(DOUT, SCK);


void setup()
{
  pinMode(gnd, OUTPUT);
  analogWrite(gnd, 0);
  pinMode(vcc, OUTPUT);
  analogWrite(vcc, 254);
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  pinMode(buzzer, OUTPUT);


  digitalWrite(relay1, LOW);
  digitalWrite(relay2, LOW);
  digitalWrite(buzzer, LOW);


  delay(1000);


  digitalWrite(relay1, HIGH);
  digitalWrite(relay2, HIGH);
  digitalWrite(buzzer, HIGH);


  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor (0, 0);


  lcd.print("Check Weigher");
  lcd.setCursor (0, 1);
  lcd.print("By SSiha");
  delay(3000);
  lcd.clear();
  lcd.print("WARNING");
  lcd.setCursor (0, 1);
  lcd.print("Max Cap. 5Kg");
  delay(3000);
  scale.set_scale();


  scale.set_scale(-252.f);
  scale.tare();
  process = 1;
  lcd.clear();


  lcd.print("Input ABC #=Entr");
  lcd.setCursor (0, 1);
  lcd.print("D = Disp/Start");
}


void main_process ()
{
  lcd.clear();
  lcd.setCursor (0, 0);


  lcd.print("Empt  Full  Max.");
  lcd.setCursor (0, 1);
  lcd.print (Wt1);
  lcd.setCursor (6, 1);
  lcd.print (Wt2);
  lcd.setCursor (12, 1);
  lcd.print (Wt3);
  delay(3000);
  lcd.clear();
  scale.power_down();
  delay(500);
  scale.power_up();
  int b = (scale.get_units());
  lcd.clear();
  lcd.setCursor (0, 0);
  weight = b * callibaration;
  if (weight <= 0)
    weight = 0;
  lcd.print(weight);
  lcd.print(" gram");


  if (weight >= Wt1)
  {
    digitalWrite(relay1, LOW);
  }
  else
    digitalWrite(relay1, HIGH);


  if (weight >= Wt2)
  {
    digitalWrite(relay2, LOW);
    digitalWrite(relay1, HIGH);
  }
  else
    digitalWrite(relay2, HIGH);




  if (weight >= Wt3)
  {
    digitalWrite(relay2, HIGH);


    digitalWrite(buzzer, LOW);
  }
  else
    digitalWrite(buzzer, HIGH);


  process = 1;
}


void loop1()
{
  Wt1 = GetNumber();
  Wt2 = GetNumber();
  Wt3 = GetNumber();
}


void  set_Wt1 ()   //
{
  relay 1
  lcd.clear();
  lcd.setCursor(0, 0);


  lcd.print("Empty Crtn Wt.");
  lcd.setCursor(0, 1);
  Wt1 = GetNumber();
  lcd.clear();
  lcd.print(Wt1);
  lcd.print(" gram");
}


void  set_Wt2 ()   //
{
  // relay 2
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Full Crtn Wt.");
  lcd.setCursor(0, 1);
  Wt2 = GetNumber();
  lcd.clear();
  lcd.print(Wt2);
  lcd.print(" gram");
}


void  set_Wt3 ()   // buzzer
{
  lcd.clear();
  lcd.setCursor(0, 0);


  lcd.print("Maximum Wt.");
  lcd.setCursor(0, 1);
  Wt3   = GetNumber();
  lcd.clear();
  lcd.print(Wt3);
  lcd.print(" gram");
}




int GetNumber()
{
  int num = 0;
  char key = kpd.getKey();
  while (key != '#')
  {
    switch (key)
    {
      case NO_KEY:
        break;


      case '0':
      case '1': case '2': case '3': case '4':
      case '5':
      case '6': case '7': case '8': case '9':


        lcd.print(key);
        num = num * 10 + (key - '0');
        break;


      case 'A':
        set_Wt1 ();


      case 'B':
        set_Wt2 ();


      case 'C':
        set_Wt3 ();


      case 'D':
        break;


    }


    key = kpd.getKey();


  }
  return num;
}


loop()
{
  loop1 ();
  main_process ();
}

First of all some indication: It is better to use byte variable when they don't have to be higher than 255. It is better add the world 'const' before a variable declaration when its value mustn't change 3) there are some very similar functions (like the 3 set_WT). You can make only one function witch this passages: Create an array witch the free variables of wt Create a function when you pass an argument. The argument will be the index of the array where the function has to work. The function text is the common parts of the free previous functions, corrected like it have to be. When you call the function you pass the correct index.

I think there are many things like this, see it better.

I know those corrections don't fix any problem, but they help the correction passage

christop: Try removing "void" from before "main_process", not from before "loop".

Also, in the future, please copy and paste a complete error message, rather than mis-typing part of the error message.

Hi Christop - I tried but it did not work

Silente: First of all some indication: It is better to use byte variable when they don't have to be higher than 255. It is better add the world 'const' before a variable declaration when its value mustn't change 3) there are some very similar functions (like the 3 set_WT). You can make only one function witch this passages: Create an array witch the free variables of wt Create a function when you pass an argument. The argument will be the index of the array where the function has to work. The function text is the common parts of the free previous functions, corrected like it have to be. When you call the function you pass the correct index.

I think there are many things like this, see it better.

I know those corrections don't fix any problem, but they help the correction passage

Hi Silente - thanks for kind suggestion - I'm trying to understand your inputs but being New to field finding it deifficult to implement - still let me give a try - I know that's too much to ask but if yon help me with edited sketch

ssinha:
Hi Christop - I tried but it did not work

“It did not work.” is the worst possible problem description if you want help.
Post your code. Describe what you want your sketch to do. Describe what it is actually doing. If it won’t compile, post the complete error messages copied from the text box below the sketch. If there is output on Serial Monitor you can copy and paste that output if it helps demonstrate what is going wrong.

Sorry John for incomplete details - sketch is already shared in earlier posts. The sketch is intended to give alarm for under/ok/over weight of object under test - where the three limts are set by 4x4 keypad

Anyhow guys - ISSUE HAS BEEN RESLOVED - after lot of efforts , when “WHILE” statement was put with main process loop - IT WORKED. Thanks for the efforts to help me.

The program is now responding as desired