0% found this document useful (0 votes)
20 views2 pages

Chapter 11

The setDebounceTime library function sets a delay in milliseconds before accepting a new key press, with a default of 10 ms if not specified. An Arduino C program is designed to transmit the state of a 3x4 numeric matrix keypad at a baud rate of 9600, indicating different key states such as 'PRESSED', 'HOLD', 'RELEASED', and 'IDLE'. The program also incorporates debounce and hold times for key events.

Uploaded by

khatidenickese
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views2 pages

Chapter 11

The setDebounceTime library function sets a delay in milliseconds before accepting a new key press, with a default of 10 ms if not specified. An Arduino C program is designed to transmit the state of a 3x4 numeric matrix keypad at a baud rate of 9600, indicating different key states such as 'PRESSED', 'HOLD', 'RELEASED', and 'IDLE'. The program also incorporates debounce and hold times for key events.

Uploaded by

khatidenickese
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Chapter 11: 3, 9

Question 3:

Describe the operation of the setDebounceTime library function and discuss why it required is?

Answer
 Sets the amount of milliseconds to wait before accepting a new key press or key event.
 If the setDebounceTime () function is not called, the default time is set to 10 ms.

Question 9:

Design an Arduino C program without comments that serially transmits at 9600 baud rate, the state of
the key when pressed The Arduino row pins A5, A4, 3 and 2 along with column pins 12, 11 and 10 are
connected to a standard 3 x 4 numeric matrix keypad Additionally, set the debounce time to 10 ms and
the key press hold time to 250 ms The following serially transmitted strings:: “PRESSED”, “HOLD”,
REASED” and “IDLE“must appear on separate lines as the different states occur?

Answer
#include <Keypad.h>

byte rowPins[4] = {A5, A4, 3, 2};


byte colPins[3] = {12, 11, 10}; char
keys[4][3] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
Keypad kyp = Keypad(makeKeymap(keys), rowPins, colPins, 4, 3);

volatile boolean blinkLED = false;

void setup() { Serial.begin(9600);


kyp.setDebounceTime(10);
kyp.setHoldTime(250);
pinMode(LED_BUILTIN, OUTPUT);
kyp.addEventListener(kypEvent);
}

void loop() { char ckey =


kyp.getKey(); if (ckey) {
Serial.println(ckey);
}
if (blinkLED) {
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
delay(100);
}
}

void kypEvent(KeypadEvent key) {


switch (kyp.getState()) { case
PRESSED:
Serial.println("PRESSED");
break; case HOLD:
Serial.println("HOLD"); if (key
== '*') blinkLED = true;
break; case RELEASED:
Serial.println("RELEASED"); if
(key == '*') blinkLED = false;
break; case IDLE:
Serial.println("IDLE");
break;
}
}

You might also like