Pages: [1]   Go Down
Author Topic: Arduino LCD number adding  (Read 338 times)
0 Members and 1 Guest are viewing this topic.
Mexico
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there, im trying to get this code to work but I'm having a bit of trouble. My final objective is to get four buttons hooked up an LCD and make one button print num=1, button 2 print num=2, button 3 print num=5 and button 4 print num=10. Each time you press them they add up to a final result. I think I have to use  00 = addition; function and int num too. Im really not sure and I would appreciate some help. I think it's a fairly simple project but for some reason I can't get it to work. What I want is to add numbers,1 ,2, 5 and 10 to a final result.

#include <LiquidCrystal.h>
int value_in1=0;
int value_in2=0;
int value_in3=0;
int value_in4=0;
int flag1=0;
int flag2=0;
int flag3=0;
int flag4=0;
int number=0;
int input1=0;
int oper=0;
int output=0;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);


void setup() {
  lcd.begin(16, 2);
  lcd.print("Numbers");
  delay(1000);
   pinMode(7,INPUT);
  pinMode(8,INPUT);
  pinMode(9,INPUT);
  pinMode(10,INPUT);
   
}
 
void loop() {
  value_in1=digitalRead(7);
  value_in2=digitalRead(smiley-cool;
  value_in3=digitalRead(9);
  value_in4=digitalRead(10);
  lcd.clear();
 if ((value_in1==HIGH)&&(flag1==0)){
    flag1=1;
    }
    else {
      input1=input1+1;
    }
    number=input1;
  }
 
  else if (value_in1==LOW){
    input1=input1;
    flag1=0;
 
 
  lcd.setCursor(0,1);
      lcd.print(1);   
  }
  else{
  delay(200);
  }
}


Notes: Im not a experienced programmer, I think it's kind of a mess. I can't get it to print o work.
Logged

Tobias A.

Offline Offline
Full Member
***
Karma: 5
Posts: 113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Curly braces are a mess ({ })
Is that your question? or do you need to fix them before posting?

And that smiley is going to take some debugging - Mod, can we have code tags please?
Logged

For whom does the clock pulse? It pulses for you!

Offline Offline
Full Member
***
Karma: 5
Posts: 113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay, I have it running (well, not throwing errors)
Is value_in1 - 4 supposed to be an array?

You only deal with value_in1


using your code and adding int x - get rid of the else's for now....
 if (value_in1==HIGH)){
    x=1;
    }
.
.
.

 if (value_in4==HIGH)){
    x=10;
    }

  lcd.setCursor(0,1);
      lcd.print(x);  
  }

you need to do whatever you want with your flag etc.
Logged

For whom does the clock pulse? It pulses for you!

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13705
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Slightly modified/stripped your code to get a working start
(code not tested)
Code:

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int number = 0;

void setup()
{

  pinMode(7, INPUT);
  pinMode(8, INPUT);
  pinMode(9, INPUT);
  pinMode(10, INPUT);

  lcd.begin(16, 2);
  lcd.print("Numbers");

  delay(1000);
  lcd.clear();
  lcd.setCursor(0, 1);
  lcd.print(number);
}

void loop()
{
  // CHECK BUTTONS
  boolean keyPressed = false;
  int value_1 = digitalRead(7);
  int value_5 = digitalRead(8);
  int value_10 = digitalRead(9);
  int reset = digitalRead(10);


  // DO THE MATH
  if (value_1 == HIGH)
  {
    number += 1;
    keyPressed = true;
  }
  if (value_5 == HIGH)
  {
    number += 5;
    keyPressed = true;
  }
  if (value_10 == HIGH)
  {
    number += 10;
    keyPressed = true;
  }
  if (reset == HIGH)
  {
    number = 0;
    keyPressed = true;
  }


  // DISPLAY RESULTS 
  // but only needed to refresh when key is pressed
  if (keyPressed)
  {
    lcd.clear();
    lcd.setCursor(0,1);
    lcd.print(number);
    delay(200);        // time to release key
  }


}
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: