Hi.
I'm still new with Arduino programming and need some advice. I'm currently doing internship project at this company. I'm stuck right now on my arduino coding.
For my project i have to enter values for 2 things : how many cycles and how many time taken. This will control a solenoid valve automatically according to the value that the user inserted. User will have to pressed # to save the value, A to insert cycles value, B to insert time taken value, C to on the solenoid valve and D to stop it.
#include <LiquidCrystal.h>
#include <Keypad.h>
#include <EEPROM.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8); // For LCD
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {4, 5, 6, 7}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {15, 14, 2, 3}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS); //For keypad
int set[1]={0};
int pos=0;
int VALVE = 35; //set the valve pin
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.setCursor(4, 0);
// Set the posotion of the message.
lcd.print("WELCOME");
lcd.setCursor(2, 1);
lcd.print("PLEASE WAIT");
set[0] = EEPROM.read(0);
delay(1000);
pinMode(VALVE, OUTPUT);
Serial.begin(9600);
}
void loop()
{
lcd.setCursor(4, 0);
lcd.print("Choose:");
lcd.setCursor(0, 1);
lcd.print("A:Cycle B:Time");
char Key = keypad.getKey();
if(Key)
{
switch (Key) {
case 'A':
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("How many cycles?");
char tmpKey;
char cycle;
bool looping = true;
while(looping)
{
tmpKey = keypad.getKey();
if(tmpKey)
{
Serial.println(tmpKey);
lcd.setCursor(0,1);
lcd.print(tmpKey);
cycle = tmpKey;
if (cycle == '#')
looping = false;
}
}
}
break;
case 'B':
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("How many time taken?");
int time_taken;
time_taken = keypad.getKey()*1000;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("[C] Start [D] Stop");
char condition;
condition = keypad.getKey();
int i;
int cycle;
if( condition == 'C' )
{
for(i=0;i<cycle;i++)
{
digitalWrite(VALVE, HIGH);
delay(time_taken);
digitalWrite(VALVE, LOW);
delay(time_taken);
}
}
break;
}
}//switch fn will end here
}
}
The program that i wrote, is not function as i want. it will not save the value that i pressed using the keypad.Can someone please give me a hint, how should it look like? Thank you.
p/s: This is my first time i asked something in this forum. So forgive me if i've done something wrong with my question.