input / display logic problem

hey all,

the setup is this: 12 button keypad (phone style), 3 chars of 7 segment display. all of these items are coded and working like they should be.

what i want to be able to do is punch in any non-zero number on the keypad to be able to send to something, and have it display what you're entering while entry is happening.

the problem is i CANNOT work out how to do this properly. the startup number is 0, which then looks for the first input as the ones column. one digit numbers alone work fine, but...

after that i'm totally screwed. i can't figure out the logic for "when another key comes in, move the first number to the tens column and then make the ones column the number just entered" without the display reading out the first number twice in a row. i've tried about 10 different variations of if/then statements to try to make it work to no avail, so before i get too frustrated and start throwing electronics around the room...

can anyone help? :frowning:

void loop(){ 
  
 char customKey = cusomKeypad.getKey();
   if (customKey != NO_KEY){      // look for key presses


     if(outputnum == 0) {   // anything above default should do something
       ones = customKey;    // put first number entered in ones column
       outputnum = ones;    // set display
       tens = (ones * 10);    // second column / tens, used if another number is entered
       }
  
     if(outputnum > 9 && outputnum < 100)) {  // i hate my life
         ones = customKey; 
         outputnum = (tens + ones);
       }


  // clear everything and drop back to 0 on getting key 11
  if ( customKey == 11 ) { outputnum = 0; ones = -1; tens = -1; hundreds = -1;} 
  
  } // if:key check 


  setDisp(outputnum); // 7seg function
     
} // main loop

move the first number to the tens column and then make the ones column the number just entered

Multiply by 10?

look in the code. i have done that. what i can't sort is how to get the display to show what i want... i'm cycling 3 digitalWrite's due to the nature of my display so making it work with the constant updating is giving me trouble.

snerk4000:
look in the code. i have done that.

Well not really, because you never use tens for anything. Step through the code on paper, if you're pressing the digit keys, outputnum can never be > 9, so your use of tens will never execute.

In any event, get rid of tens altogether. Just accumulate the result you need in outputnum. As Awol said, when you get a digit key, multiply outputnum by 10, then add the key value.

Edit: clarity

the issue is the second if statement is executi

ok. i obviously haven't explained the problem properly if everyone is just saying "hey dumbass multiply by 10" when that has nothing to do with what's actually wrong.

first input: input sets ones, *10 sets tens. output = 1
second input: uses tens, input sets ones, *100 sets hundreds. output = 1X, X being whatever key is pressed.

the issue is that in my current code, the second if statement is being triggered every time the first key press happens, and if you hit "8" the display says "88". i can't figure out what combination of comparison statements wherein this doesn't happen. output+keypad input < 9? ones+tens<100 && keypadinput=9 @#$%@

this is the logic part i'm trying to get help with.

if i'm still not explaining it clearly and no one knows what the hell i'm talking about, then i have a duemilanove for sale.

if(outputnum > 9 && outputnum < 100))

We can't see all your code, but can you explain how "outputnum" can ever be > 9?

Put in a serial print before the 2nd if to let you know what outputnum actually contains.