How to keep the keypad value until another value commes???

:confused: :confused: :confused:
HI,
i wonna use a three button as a keypad that cand do 3 actions.
(the println is only for checking the input)
that is the code:

#include <Keypad.h>
const byte rows=3;
const byte cols=1;
char keys[rows][cols]={'1','2','3'}; // keypad set
byte rowpin[rows]={2,3,4};
byte colpin[cols]={5};
Keypad choice = Keypad(makeKeymap(keys),rowpin,colpin,rows,cols);

int led = 13;
int led2 = 12; // output set
int led3 = 11;

void setup() {

pinMode(led,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);

}

void loop() {
digitalWrite(led,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);

char choix = choice.getKey(); //value get

switch(choix){
case 1:
digitalWrite(led,HIGH);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
case 2:
digitalWrite(led,LOW);
digitalWrite(led2,HIGH); // :confused: NO OUTPUT
digitalWrite(led3,LOW);

case 3:
digitalWrite(led,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,HIGH);
break;}

}
:o than How to keep the keypad value until another value commes???

  1. You're turning off the LEDs at the start of loop(). That means whatever happens in the switch/case, the LEDs will be lit for only a tiny fraction of a second (too short for you to notice).
  2. I think your switch case block is missing some break statements.

Check whether a keystroke is available. Only do something if a key is pressed. You are not currently doing this.

 char key = keypad.getKey();
ย  
ย  if (key)
ย  {
ย  ย   //code here to do what you want with the key valueย  
ย  }

A smarter version would check whether there was a keypress and only act when it was different from the previous keypress, but it depends on your requirements

Fix the problem with the missing breaks in switch/case

Brattain Member ;D
THANKS A LOT.
that s the point a was lookinf for.
8) u r a boss.

:smiley: i had to use only waitForKey() insted of getKey().
:roll_eyes:

youcefaek:
:smiley: i had to use only waitForKey() insted of getKey().
:roll_eyes:

That's great if you don't mind the program twiddling its thumbs waiting for user input. As an exercise try blinking an LED whilst waiting for user input.