Hi, I need to know how to store a multi-digit input from a 4x4 keypad. My system includes an FSR, buzzer, ir sensor, 16x2 lcd, and a 4x4 keypad. What I would like to do is store the keypad input so when the FSR load reaches the entered value the buzzer goes off. Right now I have it set up to beep when the FSR reaches 100 grams.
My code:
#include <LiquidCrystal_I2C.h>
#include <SharpIR.h>
#include <Keypad.h>
#define IRPin A1
#define model 1080
SharpIR mySensor = SharpIR(IRPin, model);
LiquidCrystal_I2C lcd(0x27, 20, 4);
int distance_cm;
const int FSR_PIN = A0;
const float VCC = 4.98;
const float R_DIV = 3230.0;
int buzzer = 10;
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','#','D'} };
byte rowPins[ROWS] = {5,4,3,2};
byte colPins[COLS] = {9,8,7,6};
Keypad keypad = Keypad (makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
{
Serial.begin(9600);
pinMode(FSR_PIN, INPUT);
lcd.init();
lcd.backlight();
Serial.begin(9600);
pinMode (buzzer, OUTPUT);
}
void loop()
{
int fsrADC = analogRead(FSR_PIN);
distance_cm = mySensor.distance();
char key = keypad.getKey();
if (fsrADC != 0)
{
float fsrV = fsrADC * VCC / 1023.0;
float fsrR = R_DIV * (VCC / fsrV - 1.0);
float force;
float fsrG = 1.0 / fsrR;
if (fsrR <= 600)
force = (fsrG - 0.00075) / 0.00000032639;
else
force = fsrG / 0.000000642857;
if (force >= 100)
{ digitalWrite (buzzer, HIGH); }
else
{
noTone(buzzer);
}
lcd.setCursor(1, 0);
lcd.print("Force: " + String(force) + "g");
lcd.setCursor(0, 1);
lcd.print("Distance: " + String(distance_cm) + "cm");
delay(1000);
lcd.clear();
}
else
{}
}