Input decimal number using 4by4 keypad ?


hello !
with of "pauls" answer
(https://forum.arduino.cc/index.php?topic=57627.msg414417#msg414417)
 i able store numbers seperately, problem store decimal numbers seperately. change key pad "d" "." , change data type "int" "float" not succsses heres code try.please me. 


code: [select]


#include <keypad.h>

float v1 = 0;
float v2 = 0;
float v3 = 0;
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', '#', '.'}
};

byte rowpins[rows] = {5, 4, 3, 2};   
byte colpins[cols] = {9, 8, 7, 6};
keypad kpd = keypad( makekeymap(keys), rowpins, colpins, rows, cols );

void setup()
{
  serial.begin(9600);                     
}

void loop()
{
   v1 = getnumber();
   serial.println ();
   serial.print (v1);
   v2 = getnumber();
   v3 = getnumber();

}


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':
            num = num * 10 + (key - '0');
            break;

         case '*':
            num = 0;
            break;
      }

      key = kpd.getkey();
   }

   return num;
}

i can see in code test input of decimal point , deal it.


Arduino Forum > Using Arduino > Programming Questions > Input decimal number using 4by4 keypad ?


arduino

Comments

Popular posts from this blog

DHT11 Time out error using v0.4.1library

Sketch upload fails with Java error (___REMOVE___/bin/avrdude)!

Arduino Uno + KTY81/210 temperature sensor