Arduino, Keypad and Decimal number

Thread Starter

mussa

Joined Jun 10, 2019
45
So I wanted to to write a program that ask you to choose between two choices. One allows you to enter a fixed number and the other directly takes you in to a loop. I'm asking for guidance on how to do that? especially the decimal part sense the keypad has no decimal. I thought of using one of the keys on the keypad as a dot maybe (* as .) i'm not sure if that can work.

C:
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <Wire.h>
#include <FMTX.h>


float fm_freq; // FM frequency

const byte ROWS = 4;
const byte COLS = 4;

char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'.', '0', '#', 'D'}
};

byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup() {

  lcd.begin(16,2);
  lcd.backlight();
}

void loop() {

  char customKey = customKeypad.getKey();


  lcd.setCursor(0, 0);
  lcd.print("Press A For Loop Freq");
  lcd.setCursor(0, 1);
  lcd.print("B set your own Freq");

if (customKey = "A") {

    fmtx_init(fm_freq, USA);
    //lcd.begin(16, 2);
    //lcd.backlight();// Turn on Lcd backlight
    //lcd.noBacklight();// Turn off Lcd backlight

    lcd.setCursor(0, 1);
    lcd.print("FM freq: ");
    lcd.setCursor(10, 1);
    lcd.print(fm_freq, 1); //print the freq  on the lcd with

  } else if (customKey = "B" )
  {
    //The loop.....
  }

}
Mod edit: code tags
 
Last edited by a moderator:

be80be

Joined Jul 5, 2008
2,072
Just change this
Code:
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
To this
Code:
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'.', '0', '#', 'D'}
};
 

Thread Starter

mussa

Joined Jun 10, 2019
45
Just change this
Code:
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
To this
Code:
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'.', '0', '#', 'D'}
};
that simple... didn't see that
 

Thread Starter

mussa

Joined Jun 10, 2019
45
i know in serial monitor we can use while loop as follow:

Serial.println("Press A for a Loop and B to set your own freq ");
while(Serial.available()==0){ }
numled1blink = Serial.parseInt();

how about lcd?
 
Top