Keypad to input delay time?

Hi, Folks:

I'm Arduino noob and still trying to figure out how's everything working.
I currently got a 4x4 keypad.
I wondered if it is possible to input delay time from keypad so I can control LED flashing time (on time = off time). Here's the code I came up with.

// #include <Keypad.h>
// const byte COLS = 4; //three columns
// const byte ROWS = 4; //four rows

// char keys[ROWS][COLS] =
// { {'1','2','3','A'},
// {'4','5','6','B'},
// {'7','8','9','C'},
// {'*','0','#','D'} };

// byte rowPins[ROWS] = {2, 3, 4, 5}; //connect to the column pinouts of the keypad
// byte colPins[COLS] = {6, 7, 8, 9}; //connect to the row pinouts of the keypad

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

// int LedPin=10;
// int Duration;

// void setup()
// { Serial.begin(9600);
// Serial.println("4x4 keypad");
// pinMode(LedPin, OUTPUT); }

// void loop()
// { char key = keypad.getKey();
// if (key)
// Duration = (key)*10;
// Serial.println(Duration-480);

// digitalWrite(LedPin, HIGH);
// delay(Duration);
// digitalWrite(LedPin, LOW);
// delay(Duration);
// }

Well........... Obviousely its not working. Orz.

Any idea how to fix this code please? Many thanks for the help. :slight_smile:

#include <Keypad.h>
const byte COLS = 4;  //three columns
const byte ROWS = 4;  //four rows

char keys[ROWS][COLS] = { { '1', '2', '3', 'A' },
                          { '4', '5', '6', 'B' },
                          { '7', '8', '9', 'C' },
                          { '*', '0', '#', 'D' } };

byte rowPins[ROWS] = { 2, 3, 4, 5 };  //connect to the column pinouts of the keypad
byte colPins[COLS] = { 6, 7, 8, 9 };  //connect to the row pinouts of the keypad

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

int LedPin = 10;
int Duration;

void setup() {
  Serial.begin(9600);
  Serial.println("4x4 keypad");
  pinMode(LedPin, OUTPUT);
}

void loop() {
  char key = keypad.getKey();
  if (key)
    Duration = (key)*10;
  Serial.println(Duration - 480);

  digitalWrite(LedPin, HIGH);
  delay(Duration);
  digitalWrite(LedPin, LOW);
  delay(Duration);
}

Compiles fine.

Yes, it compiled fine, but flashing duration did not change at all.
For whatever No. I input, the LED only flashed in same sequence.

You have to uncomment it. Then put it in code tags for the forum.

Excluding the // characters, tell us what you think is happening here ?

These lines:

delay(Duration);

are not allowing keypad entry.

"Blink without delay()" will help...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.