Hello everybody!
First post here, .
Anyway, what i came here for is two things in my program that dosent execute as i think it should.
1. The program has to make a full repeat before it outputs the calculated values, why?
I want it to output them directly as they are called, but it returns zero until a another full program loop has occured. Does this have to do with the getnumbers() function?
2. As you might see, i have changed the "*" on the keypad to represent "." for my float values. but the calculations i've tried with a "." end up skewed, eg 1,25 + 135 / 2 should equal 1,3 but gave me 830~ something. does this have to do with char representation or am i missing something?
Everything else works just as i want it.
#include <Keypad.h>
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
const byte rows = 4; //four rows
const byte cols = 3; //three columns
char keys[rows][cols] = {
 {'1','2','3'},
 {'4','5','6'},
 {'7','8','9'},
 {'.','0','#'}
};
byte rowPins[rows] = {1, 2, 3, 4}; //connect to the row pinouts of the keypad
byte colPins[cols] = {5, 6, 7}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );
float startDensity;
float endDensity;
float startPulses;
float endPulses;
float avgPulses;
float avgDensity;
void setup() {
 // Give startup feedback
 lcd.begin(16, 2);
 lcd.setCursor(0, 0);
 lcd.print("Densitet's");
 lcd.setCursor(0, 1);
 lcd.print("Kalibrering");
 delay(1000);
 lcd.print(".");
 delay(1000);
 lcd.print(".");
 delay(1000);
 lcd.print(".");
 delay(1000);
 lcd.print(".");
 delay(1000);
 lcd.print(".");
 delay(1000);
 lcd.clear();
}
void loop() {
 //display feedback for user
 lcd.setCursor(0, 0);
 lcd.print("Start");
 lcd.setCursor(0, 1);
 lcd.print("Densitet");
 delay(1500);
 lcd.clear();
 lcd.setCursor(0, 0);
 delay(500);
 lcd.print("G/CM3:");
 lcd.setCursor(0, 1);
Â
 startDensity = getNumbers();
Â
 lcd.setCursor(0, 0);
 lcd.print("Start");
 lcd.setCursor(0, 1);
 lcd.print("Pulser");
 delay(1500);
 lcd.clear();
 lcd.setCursor(0, 0);
 delay(500);
 lcd.print("CPS:");
 lcd.setCursor(5, 1);
Â
 startPulses = getNumbers();
Â
 lcd.clear();
 delay(500);Â
 lcd.setCursor(0, 0);
 lcd.print("Slut");
 lcd.setCursor(0, 1);
 lcd.print("Pulser");
 delay(1500);
 lcd.clear();
 lcd.setCursor(0, 0);
 delay(500);
 lcd.print("CPS:");
 lcd.setCursor(5, 1);
Â
 endPulses = getNumbers();
Â
 lcd.clear();
 delay(500);
 lcd.setCursor(0, 0);
 lcd.print("slut");
 lcd.setCursor(0, 1);
 lcd.print("Densitet");
 delay(1500);
 lcd.clear();
 lcd.setCursor(0, 0);
 delay(500);
 lcd.print("G/CM3:");
 lcd.setCursor(0, 1);
Â
 endDensity = getNumbers();
Â
 //Display calculated values for user
 lcd.clear();
 delay(2000);
 lcd.setCursor(0, 0);
 lcd.print("Medel densitet:");
 delay(1000);
 lcd.setCursor(0, 1);
 lcd.print(avgDensity);
 delay(10000);
 lcd.clear();
 lcd.setCursor(0, 0);
 delay(500);
 lcd.print("Medel Pulser:");
 delay(1000);
 lcd.setCursor(0, 1);
 lcd.print(avgPulses);
 delay(10000);
 lcd.clear();
 delay(3000);
Â
}
//Keypad input for user
float getNumbers()
{
 float num = 0;
 char key = keypad.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':
    case '.':
      lcd.print(key);
      num = num * 10 + (key - '0');
      break;
    case '#':
      lcd.clear();
      break;
   }
   key = keypad.getKey();
 }
 return num;
Â
}
the getNumbers() is from this forum
Appriciate any help i can get with understanding this, thanks!