Keypad num & calcs — Arduino Uno simulation

An interactive Arduino Uno circuit simulation you can run free in your browser on Velxio, by leemcf.

Components

Sketch code

#include <Keypad.h>
#include <LiquidCrystal_I2C.h>

const byte rows = 4;
const byte cols = 4;

char keyNumber[rows][cols] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'},
};

byte rowsPin[rows] = {13,12,11,10};
byte colsPin[cols] = {9,8,7,6};

Keypad keypad = Keypad(makeKeymap(keyNumber), rowsPin, colsPin, rows, cols);
LiquidCrystal_I2C lcd(0x27,16,2);


void setup()
{
  lcd.init();
  lcd.backlight();
  //Serial.begin(9600);
  
  lcd.print("* is DECIMAL");
  lcd.setCursor(0,1);// Bottom row
  lcd.print("# is ENTER");
  delay(5000);// Wait 5 seconds
  lcd.clear(); // Clears the display 
  
  lcd.print("D(in) = ");
  lcd.blink(); //Displays the blinking LCD cursor
  float D = getFloatInput();
  lcd.print(D, 3); // Print with 3 decimal places
  lcd.setCursor(0,1);// Bottom row
  if (D>3){
    lcd.print("Diameter too Big");
    lcd.noBlink(); // Turns off the blinking LCD cursor
    while (1>0){}//Delay forever
  }
  lcd.setCursor(0,1);// Bottom row  
  lcd.print("L(in) = ");
  float L = getFloatInput();
  lcd.clear(); // Clears the display
  if (L>30){
    lcd.print("L(in) = ");
    lcd.print(L, 3); // Print with 3 decimal places
    lcd.setCursor(0,1);// Bottom row
    lcd.print("Too Long");
    lcd.noBlink(); // Turns off the blinking LCD cursor
    while (1>0){}//Delay forever
  }
  
  lcd.print("D=");
  lcd.print(D, 3); // Print with 3 decimal places
  lcd.print(";L=");
  lcd.print(L, 3); // Print with 3 decimal places
  lcd.setCursor(0,1);// Bottom row
  lcd.print("# if Correct");
  float bla = getFloatInput();//Continue when # pressed
  lcd.clear(); // Clears the display
  lcd.noBlink(); // Turns off the blinking LCD cursor
  
  float H = sqrt(sq(2+(D/2))-sq(2.025));//bar centerline above rollers
  float DoCL = (8+(D/2))*sqrt(2)/2;//probe horizontal dist from centerline
  float DN = 13.188-H-DoCL;//probe vertical dist below tank lip
  float Cir = PI * D;//Circumfrence
  lcd.print("Probe to Probe");
  lcd.setCursor(0,1);// Bottom row
  lcd.print("in inches");
  delay(5000);// Wait 5 seconds
  lcd.clear(); // Clears the display
  lcd.print("P2P = ");
  lcd.println(2*DoCL,3);
  lcd.setCursor(0,1);// Bottom row
  lcd.print("# if spread");
  bla = getFloatInput();//Continue when # pressed
  
}


void loop() { 
  
}


float getFloatInput() {
  float intPart = 0;
  float fracPart = 0;
  int divisor = 1;
  boolean isDec = false;
  
  while (true) {
    char key = keypad.getKey();
    if (key != NO_KEY) {
      if (key >= '0' && key <= '9') {
        if (!isDec) {
          intPart = (intPart * 10) + (key - '0');
        } else {
          fracPart = (fracPart * 10) + (key - '0');
          divisor *= 10;
        }
        Serial.print(key);
      }
      else if (key == '*') { // Press '*' for decimal point
        isDec = true;
        Serial.print('.');
      }
      else if (key == '#') { // Press '#' to finish input
        Serial.println();
        break;
      }
    }
  }
  return intPart + (float)fracPart 

More projects by leemcf