hello
i am doing my first project in arduino and i am having a problem
the project is to make a traffic light and i need the user to enter the time he wants for each light
i made the code but it doesnot work well on proteus
it keeps returning to the yellow statement
i would appreciate any respond
i think i need a function that will clear the numbers i had pressed on the keypad
int pinled1 = 8;
int pinled2 = 9;
int pinled3 = 10;
int pinled4 = 18;
int pinled5 = 19;
char Redtime[4];
char Yellowtime[4];
char Greentime[4];
#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'},
};
byte rowPins[ROWS] = {17, 16, 15, 14}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {13, 12, 11}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
void setup(){
Serial.begin(9600);
lcd.begin(16,2);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Enter Redtime:");
Redtime[0] = '0';
Redtime[1] = '0';
Redtime[2] = '0';
Redtime[3] = '0';
lcd.setCursor(0,1);
lcd.print(Redtime[0]);
lcd.print(Redtime[1]);
lcd.print(Redtime[2]);
lcd.print(Redtime[3]);
pinMode (pinled1, OUTPUT );
pinMode (pinled2, OUTPUT );
pinMode (pinled3, OUTPUT );
pinMode (pinled4, OUTPUT );
pinMode (pinled5, OUTPUT );
digitalWrite(pinled1, LOW);
digitalWrite(pinled2, LOW);
digitalWrite(pinled3, LOW);
digitalWrite(pinled4, LOW);
digitalWrite(pinled5, LOW);
}
void loop(){
char key = keypad.getKey();
lcd.setCursor(0,0);
if (key != NO_KEY )
{if (key != '#')
{Redtime[0] = Redtime[1];
Redtime[1] = Redtime[2];
Redtime[2] = Redtime[3];
Redtime[3] = key;
lcd.setCursor(0,1);
lcd.print(Redtime[0]);
lcd.print(Redtime[1]);
lcd.print(Redtime[2]);
lcd.print(Redtime[3]);}
else
{lcd.clear();
lcd.setCursor(0,0);
lcd.print("Enter Yellowtime");
Yellowtime[0] = '0';
Yellowtime[1] = '0';
Yellowtime[2] = '0';
Yellowtime[3] = '0';
lcd.setCursor(0,1);
lcd.print(Yellowtime[0]);
lcd.print(Yellowtime[1]);
lcd.print(Yellowtime[2]);
lcd.print(Yellowtime[3]);
if (key != NO_KEY )
{if (key != '#')
{Yellowtime[0] = Yellowtime[1];
Yellowtime[1] = Yellowtime[2];
Yellowtime[2] = Yellowtime[3];
Yellowtime[3] = key;
lcd.setCursor(0,1);
lcd.print(Yellowtime[0]);
lcd.print(Yellowtime[1]);
lcd.print(Yellowtime[2]);
lcd.print(Yellowtime[3]);}
else
{lcd.clear();
lcd.setCursor(0,0);
lcd.print("Enter Greentime");
Greentime[0] = '0';
Greentime[1] = '0';
Greentime[2] = '0';
Greentime[3] = '0';
lcd.setCursor(0,1);
lcd.print(Greentime[0]);
lcd.print(Greentime[1]);
lcd.print(Greentime[2]);
lcd.print(Greentime[3]);
if (key != NO_KEY)
{if (key != '#')
{Greentime[0] = Greentime[1];
Greentime[1] = Greentime[2];
Greentime[2] = Greentime[3];
Greentime[3] = key;
lcd.setCursor(0,1);
lcd.print(Greentime[0]);
lcd.print(Greentime[1]);
lcd.print(Greentime[2]);
lcd.print(Greentime[3]);}
else
{lcd.clear();
lcd.setCursor(0,0);
lcd.print("start");}}}}}}
}