Using Arduino Uno atmega328p: Build a system that will toggle the \"L led\" (the
ID: 3596123 • Letter: U
Question
Using Arduino Uno atmega328p:
Build a system that will toggle the "L led" (the built in one on pin 13 - PB5) when the correct 4 digit code is entered on the keypad.
The 4 digit code should be "hard coded" in the source code - i.e. cannot change. Place it in a char string array.
If you create a 5 element char array you can grab each keypress and put it into sequential elements.
Don't forget to have a null char '' at position 4.
If you #include <string.h> you can make use of some very handy string functions to compare your entered string of digits with your pre-stored one etc.
Explanation / Answer
#include<stdio.h>
#include<string.h>
void main()
{
char str[4]; .. initializing the input array
char passCode[] = "abcd"; // Pass Code :array of size 4 is created and this automatically insert a '/0' at the end
printf("Enter a string: ");
scanf("%[^ ]",&str); //scanning the whole string,including the white spaces
if (strcmp(str, passCode) == 0) { // comparing the values using string.h function strcmp
printf("PaassCode Match, toggle the "L led""); // passed then led is led
}else{
printf("passCode Doesnot Match"); //else not
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.