Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: TextLCD
main.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2019 ARM Limited 00003 * SPDX-License-Identifier: Apache-2.0 00004 */ 00005 00006 #include "mbed.h" 00007 #include "platform/mbed_thread.h" 00008 00009 #include <iostream> 00010 #include <sstream> 00011 #include "vector" 00012 #include "TextLCD.h" 00013 00014 TextLCD lcd(PA_9, PB_10, PB_4, PB_5, PB_3, PA_10); // rs, rw, e, d0, d1, d2, d3 00015 00016 00017 using namespace std; 00018 DigitalIn incrementbutton(PA_2); 00019 DigitalIn decrementbutton(PA_3); 00020 DigitalIn acceptbutton(PA_10); 00021 DigitalOut myled(PA_0); 00022 00023 00024 struct Attendant { 00025 char AttendantName[16]; 00026 char systemPassword[5] = "1212"; //password 00027 00028 }; 00029 int debug1 = 0; 00030 int main() 00031 { 00032 00033 std::vector<int > password{}; 00034 char str1[4]; 00035 00036 std::ostringstream oss; 00037 00038 Attendant Attendant1; 00039 00040 if (debug1 > 1) { 00041 std::cout << "Enter Attendant Name"<< std::endl; 00042 scanf("%s",&Attendant1.AttendantName); 00043 std::cout << "Welcome " << Attendant1.AttendantName << "\nSelect password\n" << std::endl; //question 1 00044 00045 } 00046 00047 00048 int check = 1; 00049 while(check) { 00050 lcd.printf("Welcome, Select password"); 00051 wait(1); 00052 lcd.cls(); 00053 00054 00055 00056 00057 00058 int count; 00059 for (count = 0; count < 10; count++) { 00060 if(password.size() < 4) { 00061 00062 00063 00064 lcd.printf("Select Number : %i",count); 00065 wait(1); 00066 lcd.cls(); 00067 00068 00069 if (debug1 > 1) { 00070 std::cout << "Select Number : " << count << " ?\n" << std::endl; 00071 scanf("%s", &str1); 00072 } 00073 00074 if (acceptbutton == 0) { //RD2 (the button configurations for RD0 will be here) 00075 password.push_back(count); 00076 //std::cout << password[(password.size() - 1)] << std::endl; 00077 count = -1; 00078 } else if (incrementbutton == 0) { //incrementing //RD0 (the button configurations for RD1 will be here) 00079 continue; 00080 } else if (decrementbutton == 0) { //RD1 (the button configurations for RD2 will be here) 00081 count--; 00082 count--; 00083 } else { 00084 lcd.printf("INValid Selection"); 00085 wait(1); 00086 lcd.cls(); 00087 00088 if (debug1 > 1) { 00089 std::cout << "Enter A Valid Selection\n" << std::endl; 00090 } 00091 } 00092 00093 } 00094 } 00095 00096 std::copy(password.begin(),password.end(),std::ostream_iterator<int>(oss)); 00097 00098 std::string result = oss.str(); 00099 const char *c_result = result.c_str(); 00100 00101 if(!strcmp(c_result,Attendant1.systemPassword)) { 00102 lcd.printf("%s", c_result); 00103 lcd.printf("\n"); 00104 wait(1); 00105 lcd.cls(); 00106 check = 0; 00107 } else { 00108 // std::cout << "password incorrect\n" << "Try Again" << std::endl; 00109 00110 lcd.printf("incorrect Try Again"); 00111 wait(1); 00112 lcd.cls(); 00113 password.clear(); 00114 } 00115 00116 00117 } 00118 return 0; 00119 }; 00120 00121 00122 00123 00124 00125
Generated on Tue Jul 26 2022 06:37:53 by
1.7.2