simple Calculator Program??

Hi Guys ,

I want to create a program with arduino UNO to calculate a number + number … using :

  1. LCD to type “what is 1st number?” and “what is 2nd number?” …etc.

2)button as a “next” the questions.

3)button as a “counter” .

That’s My code :

#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

int next_but = 8;
int number_but = 9;

int i = 0;

int next_but_state;
int next_but_state2;
int next_but_state3;
int number_but_state;
int last_number_but_state;

void setup() {
  // put your setup code here, to run once:
  lcd.begin(16, 2);
  pinMode(next_but, INPUT_PULLUP);
  pinMode(number_but, INPUT_PULLUP);

  lcd.print("Hello In My CLC");

}

void loop() {
  // put your main code here, to run repeatedly:
  next_but_state = digitalRead(next_but);
  number_but_state = digitalRead(number_but);
  if (next_but_state == LOW)
  {
    lcd.clear();
    lcd.print("What is 1st No?");
    next_but_state2 = digitalRead(next_but);
    if (next_but_state2 == LOW)
    {
      lcd.clear();
      lcd.print("What is 2nd No?");
      next_but_state3 = digitalRead(next_but);
      if (next_but_state3 == LOW)
      {
        lcd.clear();
        lcd.print("The Result is = ");
      }
    }
  }
  if (number_but_state != last_number_but_state) {
    if (number_but_state == LOW)
    {
      i ++;
      lcd.setCursor(1, 1);
      lcd.print (i);
    }
  }
  last_number_but_state = number_but_state;
}

the order of the question…It isn’t correct

How do you enter the two numbers? An other keypad?

Jacques

Your code needs to be completely rewritten.

You need to consider what should happen on each pass through loop(). The user may have pressed the next switch. Or not. You need to keep track of how many times that has happened, so you can display the appropriate message.

jbellavance:
How do you enter the two numbers? An other keypad?

Jacques

by the number button like counter

Then as PaulS said, you need to re-think your sketch. You need to find out all that is needed to enter a number and to remember what those two numbers are.

Jacques

PaulS:
Your code needs to be completely rewritten.

You need to consider what should happen on each pass through loop(). The user may have pressed the next switch. Or not. You need to keep track of how many times that has happened, so you can display the appropriate message.

jbellavance:
Then as PaulS said, you need to re-think your sketch. You need to find out all that is needed to enter a number and to remember what those two numbers are.

Jacques

thanks for replying ...

I'll try ...