Answered step by step
Verified Expert Solution
Question
1 Approved Answer
privided is my code, what do i change my code in order to make the led 1 turn on when code 2 7 5 3
privided is my code, what do i change my code in order to make the led turn on when code # is entered and led off when is entered. here is my code:
#include
#include
#include "mbed.h
#define NUMROWS
#define NUMCOLS
#define ROWACTIVETIME ms
Define the key map
char keymapNUMROWSNUMCOLS
Ast row
Bnd row
Crd row
#Dth row
;
Define the LED
DigitalOut LEDLED;
DigitalOut ROWPA;
DigitalOut ROWPA;
DigitalOut ROWPB;
DigitalOut ROWPC;
DigitalIn COLPA PullUp;
DigitalIn COLPA PullUp;
DigitalIn COLPB PullUp;
DigitalIn COLPB PullUp;
Function to scan the columns
int colscan
if COL
return ;
else if COL
return ;
else if COL
return ;
else if COL
return ;
else
return ;
Function to scan the keypad
char keypadscan
static char sequence; Initialize sequence with zeros
static int seqindex ;
for int i ; i ; i
Select the current row
switch i
case :
ROW; ROW; ROW; ROW;
break;
case :
ROW; ROW; ROW; ROW;
break;
case :
ROW; ROW; ROW; ROW;
break;
case :
ROW; ROW; ROW; ROW;
break;
Poll for key press
int col colscan;
if col
Key pressed
char key keymapicol;
if seqindex Keep track of the sequence until it reaches characters
sequenceseqindex key;
if seqindex Check if the sequence matches #
if strcmpsequence#
LED; Turn on LED
if key Check if is pressed
LED; Turn off LED
return key;
Delay to stabilize
ThisThread::sleepforms;
No key pressed
return ;
int main
while
char key keypadscan;
if key
printfKey pressed: cr
key;
Do something with the key
ThisThread::sleepforms; Adjust the delay as needed
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started