82Views1Replies

Author Options:

when typing numbers from keypad ex: (1) it types (50) or something like this , this is a traffic project ? Answered

              i have a traffic project which contains led for cars and led for people  first i have to type numbers of seconds for each led  (red,yellow,green)    but when typing 5 from keypad it types 2 digits as 52   please if you could help me






              #include <LiquidCrystal.h>

#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] = {31,33,35,37};
byte colPins[COLS] = {39,41,43};

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
LiquidCrystal lcd(19,18,17,16,15,14);

const int ledpinG1 = 13;
const int ledpinY1 = 12;
const int ledpinR1 = 11;
const int ledpinG2 = 9;
const int ledpinR2 = 8;



void setup() {
  lcd.begin(16, 2);
  delay(1000);


  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);

}

void loop() {

   char key = keypad.getKey();

  digitalWrite(13, HIGH);
  digitalWrite(8, HIGH); 
  lcd.setCursor(9, 0);
lcd.print("GREEN");
lcd.setCursor(9, 1);
lcd.print("RED");
  if (key != NO_KEY){
    for(int i=key;i>-1;i--){
    lcd.setCursor(0,0);
    lcd.print(i);
    delay(1000);

   }}
    lcd.clear();



digitalWrite(13, LOW);   
  digitalWrite(12, HIGH);
  digitalWrite(8, HIGH);
  lcd.setCursor(9, 0);
lcd.print("YELLOW");
  lcd.setCursor(9, 1);
lcd.print("RED");
if (key != NO_KEY){
for(int i=key;i>-1;i--){
       lcd.setCursor(0,0);
    lcd.print(i);
delay(1000);

        }}
lcd.clear();



   digitalWrite(12, LOW);
  digitalWrite(8, LOW); 
  digitalWrite(11, HIGH);
  digitalWrite(9,HIGH); 
  lcd.setCursor(9, 0);
lcd.print("RED");
   lcd.setCursor(9, 1);
lcd.print("GREEN");
  if (key != NO_KEY){
for(int i=key;i>-1;i--){
     lcd.setCursor(0,0);
    lcd.print(i);
    delay(1000);
    }}

lcd.clear();
digitalWrite(11, LOW);
digitalWrite(9, LOW);








}


Tags:arduino

Comments

The forums are retiring in 2021 and are now closed for new topics and comments.
0
steveastrouk
steveastrouk

5 years ago

You have "key bounce"

Wait until a Getkey returns nokey, and see what happens.