milk station

the code should do this :
When I start arduino , display asks for The amount of milk and store it in a variable for later use in calculations.

Then when milk starts to flow(using flow sensor), the display outputs flowing litres and equivalent the amount of milk requested until stoped, just like in Gas stations.

there is a lot that i have to add but for now here is the main code.
thankyou

#include <LiquidCrystal.h>

#define ENA 10  //enable pin for motor

#include <Keypad.h> 

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

const byte ROWS = 4; // Four rows
const byte COLS = 4; // columns

// Define the Keymap
char keys[ROWS][COLS] = {
{‘1’,‘2’,‘3’,‘E’}, // E - Enter
{‘4’,‘5’,‘6’,‘S’}, // S - Stop
{‘7’,‘8’,‘9’,‘B’},
{‘D’,‘0’,‘A’,‘C’}
};

//Input
int userInput = 0;

//Flow Meter Variables
volatile int nbTopsFan; //measuring the rising edges of the signal
int calc;
int hallSensor = 2; //The pin location of the sensor
float totalFlowed = 0;

//

byte rowPins[ROWS] = { 9,8,7,6 };// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte colPins[COLS] = { 5,4,3,2, };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.

// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup()
{

//set all of the outputs
pinMode(ENA, OUTPUT); //Motor Pin
pinMode(hallSensor, INPUT); //initializes digital pin 2 as an input

lcd.begin(20, 4); // initialize the lcd

Serial.begin(9600);

attachInterrupt(0, rpm, RISING); //and the interrupt is attached
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
}

void loop(){
keypad.getKey();
int enablePin = digitalRead(10);
if (enablePin==HIGH) {
fanControl();
}

if(totalFlowed >= userInput ) {
stopMotor();
totalFlowed = 0; //reset total flow
}
}

//take care of some special events
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
//
Serial.print("Pressed: ");
Serial.println(eKey);

//check which key is pressed
switch (eKey){
case ‘E’: startMotor(); break;
case ‘S’: stopMotor(); break;

case ‘0’ … ‘9’: // This keeps collecting the first value until a operator is pressed “±*/”
lcd.setCursor(0,0);
userInput = userInput * 10 + (eKey - ‘0’);
lcd.print(userInput);
break;
default: break;
}
}
}

void startMotor() {
digitalWrite(ENA, HIGH);

// digitalWrite(ENA, LOW);
}

void stopMotor(){
digitalWrite(ENA, LOW);
}

//control fan
void fanControl() {
nbTopsFan = 0; //Set NbTops to 0 ready for calculations
sei(); //Enables interrupts
delay (1000); //Wait 1 second
cli(); //Disable interrupts
calc = (nbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q = flow rate in L/hour

totalFlowed = totalFlowed + calc/3600;

Serial.print (calc, DEC); //Prints the number calculated above
Serial.print (" L/hour\r\n"); //Prints “L/hour” and returns a new line
}

void rpm () { //This is the function that the interupt calls
nbTopsFan++; //This function measures the rising and falling edge of signal
}

milk_project.ino (2.96 KB)

OK, so what's the problem?

What's the point of the first line of loop that checks for a key and then throws away any returned value?