Arduino LCD Keypad, entering number values as a multiplier

Hi, I'm just a beginner at arduino. So, here's my problem, I'm working on my project, my project is a power meter with displayed price. The time, and kilowatt meter is okay. But when I enter a numbers in the per kilowatt hour price, as I go to the next page, the numbers i entered are back to 0, what should I do?

Keeie:
Hi, I'm just a beginner at arduino. So, here's my problem, I'm working on my project, my project is a power meter with displayed price. The time, and kilowatt meter is okay. But when I enter a numbers in the per kilowatt hour price, as I go to the next page, the numbers i entered are back to 0, what should I do?

Do you seriously expect us to guess?

Keeie:
as I go to the next page, the numbers i entered are back to 0, what should I do?

Maybe make some changes to the program that you have not posted?

...R

In the playground section I think there is an example on this sort of thing

Hi! I'm just a beginner in arduino and I'm working on a project which is a arduino power meter with price. My problem is that as I type a numbers from the keypad in the case 1, when I go to the next cases, the numbers that I typed in case 1 is gone. I also reduce the keypad pins from 7 pins to 1 pin can someone help me? i'm just a beginner in arduino. thank you!

Here is my code:

#include <Wire.h>
#include <LiquidCrystal.h>
#include "EmonLib.h"
LiquidCrystal lcd(13,12,5,4,3,2);

#define MILLIS_OVERFLOW 34359738
unsigned long currentMillis, previousMillis, elapsedMillis;
int seconds, minutes, hours;

// Code for Voltage and Current Sensor
#define VOLT_CAL 549
#define CURRENT_CAL 65
EnergyMonitor emon1; 

// Code for Keypad
int thresholds[11]= {42, 21, 0, 127, 110, 92, 199, 185, 169, 248, 235};
char keypad[11] = {'1', '2', '.', '4', '5', '6', '7', '8', '9', '0', '3'};

// Code for Lcd Menu 
int count=0;
int h;
int m;
int s;
int p;
const int numOfInputs = 1;
const int inputPins[numOfInputs] = {9};
int inputState[numOfInputs];
int lastInputState[numOfInputs] = {LOW};
bool inputFlags[numOfInputs] = {LOW};
long lastDebounceTime[numOfInputs] = {0};
long debounceDelay = 5;

//LCD MENU LOGIC
const int numOfScreens = 5;
int currentScreen = 0;
String screens[numOfScreens][5] = {{"Price(Php):"},{"Per kwh(Php):"},{"Time(hrs:min:sec:)"},{"Power(kW):"},{"Current(A):","Voltage(V):"}};
int parameters[numOfScreens];


void setup() {

  emon1.voltage(1,VOLT_CAL, 1.7);
  emon1.current(0, CURRENT_CAL);
for(int i=0; i< numOfInputs; i++){
  pinMode(inputPins[i], INPUT);
  digitalWrite(inputPins[i], HIGH);
}
lcd.begin(20,4);

}

void loop() {
  // put your main code here, to run repeatedly:
  emon1.calcVI(20,2000);
 double Irms = emon1.calcIrms(1480);
  float currentDraw    = emon1.Irms;            
  float supplyVoltage  = emon1.Vrms;

  
switch (currentScreen){
  case 0:{
    h= hours;
    m= minutes/60;
    s= seconds/3600;
    p= (//input value from case 2*(//input value from case 1 of keypad)*((currentDraw*supplyVoltage)/1000));
    lcd.setCursor(0,1);
    lcd.print(p,2);
  }
  break;
case 1: {
   int value =  analogRead(A2);
  
for(int i=0; i<12; i++)
{
    if ( abs(value - thresholds[i]) <3 )
    {
      
      lcd.print(keypad[i]);
      while (analogRead (A2) < 1000) {delay(80);}
      count++;
      
      if (count==5)
      {
      lcd.setCursor(0,1);  
        count=0;
     
      
      }
    }
}
}
break;
case 2:{
setClock();
lcd.setCursor(0,1);
lcd.print(hours);
lcd.print(":");
lcd.print(minutes);
lcd.print(":");
lcd.print(seconds);
lcd.print(":");
}
break;
case 3:{
 lcd.setCursor(0,1);
   lcd.print((currentDraw*supplyVoltage)/1000);
}
break;
case 4:{
   lcd.setCursor(12,0);

  lcd.print(currentDraw);
   lcd.setCursor(12,1);
  lcd.print(supplyVoltage);

}
}

  

setInputFlags();
resolveInputFlags();
}


  
void setInputFlags(){
  for(int i=0; i< numOfInputs; i++){
    int reading = digitalRead(inputPins[i]);
    if (reading != lastInputState[i]) {
      lastDebounceTime[i] = millis();
    }
    if ((millis() - lastDebounceTime[i]) > debounceDelay) {
      if (reading != inputState[i]) {
        inputState[i] = reading;
        if (inputState[i] == HIGH) {
          inputFlags[i] = HIGH;
        }
      }
    }
    lastInputState[i] = reading;
  }
}

void resolveInputFlags() {
  for(int i = 0; i < numOfInputs; i++) {
    if(inputFlags[i] == HIGH){
    inputAction(i);
    Serial.println(currentScreen);
    inputFlags[i] = LOW;
    printScreen();
    
  }
}
}
void inputAction(int input) {
  if(input == 0) {
    if (currentScreen == 0) {
      currentScreen = numOfScreens-1;
    }else{
      currentScreen--;
        }
    }
  }


void printScreen(){
  lcd.clear();
  lcd.print(screens[currentScreen][0]);
  lcd.setCursor(0,1);
  lcd.print(screens[currentScreen][1]);
}
void setClock(){
  currentMillis = millis();
  if(currentMillis < previousMillis){
    elapsedMillis += MILLIS_OVERFLOW - previousMillis + currentMillis;
  
}else{
  elapsedMillis += currentMillis - previousMillis;
}
  if (elapsedMillis > 999){
    seconds++;
    elapsedMillis = elapsedMillis - 1000;
  }

  if (seconds == 60){
    minutes++;
    seconds = 0;
  }

  if (minutes == 60){
    hours++;
    minutes=0;
  }
  if(hours == 8760){
    hours = 0;
  }

  previousMillis = currentMillis;
}

DON'T CROSS POST!!!!!!!!!!!!!!!!!!!!

I HAVE REPORTED THIS THREAD TO THE MODERATORS

Duplicate posts waste the time of the people helping you. I might spend 15 minutes writing a detailed answer on this thread, without knowing that someone already did the same in the other thread. This behavior is very disrespectful to the people you're asking for assistance. Just because we give our time freely doesn't mean it has no value.

In the future, take some time to pick the forum section that best suits the topic of your question and then only post once to that forum section. This is basic forum etiquette, which you would already know if you had bothered reading the sticky "How to use this forum - please read." post you will find at the top of every forum section. It contains a lot of other useful information. Please read it.

okay, i'm sorry. i'll just delete the other post

Sorry, I didn't post my code, but there you go. please help me! :frowning:
Here is my code:

#include <Wire.h>
#include <LiquidCrystal.h>
#include "EmonLib.h"
LiquidCrystal lcd(13,12,5,4,3,2);

#define MILLIS_OVERFLOW 34359738
unsigned long currentMillis, previousMillis, elapsedMillis;
int seconds, minutes, hours;

// Code for Voltage and Current Sensor
#define VOLT_CAL 549
#define CURRENT_CAL 65
EnergyMonitor emon1; 

// Code for Keypad
int thresholds[11]= {42, 21, 0, 127, 110, 92, 199, 185, 169, 248, 235};
char keypad[11] = {'1', '2', '.', '4', '5', '6', '7', '8', '9', '0', '3'};

// Code for Lcd Menu 
int count=0;
int h;
int m;
int s;
int p;
const int numOfInputs = 1;
const int inputPins[numOfInputs] = {9};
int inputState[numOfInputs];
int lastInputState[numOfInputs] = {LOW};
bool inputFlags[numOfInputs] = {LOW};
long lastDebounceTime[numOfInputs] = {0};
long debounceDelay = 5;

//LCD MENU LOGIC
const int numOfScreens = 5;
int currentScreen = 0;
String screens[numOfScreens][5] = {{"Price(Php):"},{"Per kwh(Php):"},{"Time(hrs:min:sec:)"},{"Power(kW):"},{"Current(A):","Voltage(V):"}};
int parameters[numOfScreens];


void setup() {

  emon1.voltage(1,VOLT_CAL, 1.7);
  emon1.current(0, CURRENT_CAL);
for(int i=0; i< numOfInputs; i++){
  pinMode(inputPins[i], INPUT);
  digitalWrite(inputPins[i], HIGH);
}
lcd.begin(20,4);

}

void loop() {
  // put your main code here, to run repeatedly:
  emon1.calcVI(20,2000);
 double Irms = emon1.calcIrms(1480);
  float currentDraw    = emon1.Irms;            
  float supplyVoltage  = emon1.Vrms;

  
switch (currentScreen){
  case 0:{
    h= hours;
    m= minutes/60;
    s= seconds/3600;
    p= (//input value from case 2*(//input value from case 1 of keypad)*((currentDraw*supplyVoltage)/1000));
    lcd.setCursor(0,1);
    lcd.print(p,2);
  }
  break;
case 1: {
   int value =  analogRead(A2);
  
for(int i=0; i<12; i++)
{
    if ( abs(value - thresholds[i]) <3 )
    {
      
      lcd.print(keypad[i]);
      while (analogRead (A2) < 1000) {delay(80);}
      count++;
      
      if (count==5)
      {
      lcd.setCursor(0,1);  
        count=0;
     
      
      }
    }
}
}
break;
case 2:{
setClock();
lcd.setCursor(0,1);
lcd.print(hours);
lcd.print(":");
lcd.print(minutes);
lcd.print(":");
lcd.print(seconds);
lcd.print(":");
}
break;
case 3:{
 lcd.setCursor(0,1);
   lcd.print((currentDraw*supplyVoltage)/1000);
}
break;
case 4:{
   lcd.setCursor(12,0);

  lcd.print(currentDraw);
   lcd.setCursor(12,1);
  lcd.print(supplyVoltage);

}
}

  

setInputFlags();
resolveInputFlags();
}


  
void setInputFlags(){
  for(int i=0; i< numOfInputs; i++){
    int reading = digitalRead(inputPins[i]);
    if (reading != lastInputState[i]) {
      lastDebounceTime[i] = millis();
    }
    if ((millis() - lastDebounceTime[i]) > debounceDelay) {
      if (reading != inputState[i]) {
        inputState[i] = reading;
        if (inputState[i] == HIGH) {
          inputFlags[i] = HIGH;
        }
      }
    }
    lastInputState[i] = reading;
  }
}

void resolveInputFlags() {
  for(int i = 0; i < numOfInputs; i++) {
    if(inputFlags[i] == HIGH){
    inputAction(i);
    Serial.println(currentScreen);
    inputFlags[i] = LOW;
    printScreen();
    
  }
}
}
void inputAction(int input) {
  if(input == 0) {
    if (currentScreen == 0) {
      currentScreen = numOfScreens-1;
    }else{
      currentScreen--;
        }
    }
  }


void printScreen(){
  lcd.clear();
  lcd.print(screens[currentScreen][0]);
  lcd.setCursor(0,1);
  lcd.print(screens[currentScreen][1]);
}
void setClock(){
  currentMillis = millis();
  if(currentMillis < previousMillis){
    elapsedMillis += MILLIS_OVERFLOW - previousMillis + currentMillis;
  
}else{
  elapsedMillis += currentMillis - previousMillis;
}
  if (elapsedMillis > 999){
    seconds++;
    elapsedMillis = elapsedMillis - 1000;
  }

  if (seconds == 60){
    minutes++;
    seconds = 0;
  }

  if (minutes == 60){
    hours++;
    minutes=0;
  }
  if(hours == 8760){
    hours = 0;
  }

  previousMillis = currentMillis;
}

Seems to be time to add some Serial.print() code to begin to track down the problem.

Paul

Threads merged.

Paul_KD7HB:
Seems to be time to add some Serial.print() code to begin to track down the problem.

Paul

where should i add serialprint?

Keeie:
where should i add serialprint?

Based on your first posting, I guess it would be before and after every use of the variable that is being set to zero.

Paul