4180 Final Project

Dependencies:   4DGL-uLCD-SE mbed Servo

Committer:
pshabbaki3
Date:
Tue Apr 12 15:29:07 2016 +0000
Revision:
0:5d35ff3dc9a5
Child:
1:dd048edb2716
Child:
2:693a3af5af49
IoT Front Door Lock

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pshabbaki3 0:5d35ff3dc9a5 1 #include "mbed.h"
pshabbaki3 0:5d35ff3dc9a5 2 #include <string>
pshabbaki3 0:5d35ff3dc9a5 3 #include <vector>
pshabbaki3 0:5d35ff3dc9a5 4 #include <iostream>
pshabbaki3 0:5d35ff3dc9a5 5 #include <sstream>
pshabbaki3 0:5d35ff3dc9a5 6 #include <iterator>
pshabbaki3 0:5d35ff3dc9a5 7 #include <stdio.h>
pshabbaki3 0:5d35ff3dc9a5 8 #include <ctype.h>
pshabbaki3 0:5d35ff3dc9a5 9 #include "uLCD_4DGL.h"
pshabbaki3 0:5d35ff3dc9a5 10
pshabbaki3 0:5d35ff3dc9a5 11
pshabbaki3 0:5d35ff3dc9a5 12 DigitalOut myled(LED1);
pshabbaki3 0:5d35ff3dc9a5 13 Serial pc(USBTX,USBRX);
pshabbaki3 0:5d35ff3dc9a5 14 uLCD_4DGL lcd(p28,p27,p30); // serial tx, serial rx, reset pin;
pshabbaki3 0:5d35ff3dc9a5 15
pshabbaki3 0:5d35ff3dc9a5 16
pshabbaki3 0:5d35ff3dc9a5 17 vector<char> im;
pshabbaki3 0:5d35ff3dc9a5 18 vector<char> vec;
pshabbaki3 0:5d35ff3dc9a5 19 vector<char> name;
pshabbaki3 0:5d35ff3dc9a5 20 vector<char> final;
pshabbaki3 0:5d35ff3dc9a5 21
pshabbaki3 0:5d35ff3dc9a5 22
pshabbaki3 0:5d35ff3dc9a5 23 int i = 0;
pshabbaki3 0:5d35ff3dc9a5 24
pshabbaki3 0:5d35ff3dc9a5 25 void checkResult(vector<char> vec, vector<char> name)
pshabbaki3 0:5d35ff3dc9a5 26 {
pshabbaki3 0:5d35ff3dc9a5 27 // This function will check the keypad values and check if the passcode exists or not
pshabbaki3 0:5d35ff3dc9a5 28
pshabbaki3 0:5d35ff3dc9a5 29 vector<char> ans; //This vector should be the values coming from keypad
pshabbaki3 0:5d35ff3dc9a5 30 ans.push_back('1');
pshabbaki3 0:5d35ff3dc9a5 31 ans.push_back('2');
pshabbaki3 0:5d35ff3dc9a5 32 ans.push_back('3');
pshabbaki3 0:5d35ff3dc9a5 33 ans.push_back('4');
pshabbaki3 0:5d35ff3dc9a5 34 ans.push_back('5');
pshabbaki3 0:5d35ff3dc9a5 35 ans.push_back('6');
pshabbaki3 0:5d35ff3dc9a5 36 if (vec.size()==6) {
pshabbaki3 0:5d35ff3dc9a5 37 i++; //use "i" to find which person logged in.
pshabbaki3 0:5d35ff3dc9a5 38 if (ans == vec) {
pshabbaki3 0:5d35ff3dc9a5 39 // pc.printf("Found");
pshabbaki3 0:5d35ff3dc9a5 40 lcd.printf("\nFound\n");
pshabbaki3 0:5d35ff3dc9a5 41 final = name;
pshabbaki3 0:5d35ff3dc9a5 42 final.insert(name.end(),vec.begin(),vec.end());
pshabbaki3 0:5d35ff3dc9a5 43
pshabbaki3 0:5d35ff3dc9a5 44 } else {
pshabbaki3 0:5d35ff3dc9a5 45 // pc.printf("not found");
pshabbaki3 0:5d35ff3dc9a5 46 lcd.printf("\nnot found\n");
pshabbaki3 0:5d35ff3dc9a5 47 final.clear();
pshabbaki3 0:5d35ff3dc9a5 48 }
pshabbaki3 0:5d35ff3dc9a5 49 }
pshabbaki3 0:5d35ff3dc9a5 50 }
pshabbaki3 0:5d35ff3dc9a5 51
pshabbaki3 0:5d35ff3dc9a5 52
pshabbaki3 0:5d35ff3dc9a5 53 void checkKeyboard(char c)
pshabbaki3 0:5d35ff3dc9a5 54 {
pshabbaki3 0:5d35ff3dc9a5 55 if (c ==' ') {
pshabbaki3 0:5d35ff3dc9a5 56 checkResult(vec,name);
pshabbaki3 0:5d35ff3dc9a5 57 vec.clear();
pshabbaki3 0:5d35ff3dc9a5 58 name.clear();
pshabbaki3 0:5d35ff3dc9a5 59 final.clear();
pshabbaki3 0:5d35ff3dc9a5 60 // pc.printf("clear");
pshabbaki3 0:5d35ff3dc9a5 61 lcd.printf("clear");
pshabbaki3 0:5d35ff3dc9a5 62 } else {
pshabbaki3 0:5d35ff3dc9a5 63 if (isdigit(c)) {
pshabbaki3 0:5d35ff3dc9a5 64 // write numbers (char) to vector vec
pshabbaki3 0:5d35ff3dc9a5 65 vec.push_back(c);
pshabbaki3 0:5d35ff3dc9a5 66 // pc.printf("\nnumber %c\n",c);
pshabbaki3 0:5d35ff3dc9a5 67 } else if (isalpha(c)) {
pshabbaki3 0:5d35ff3dc9a5 68 // write letters (char) to vector name
pshabbaki3 0:5d35ff3dc9a5 69 name.push_back(c);
pshabbaki3 0:5d35ff3dc9a5 70 // pc.printf("\nname %c\n",c);
pshabbaki3 0:5d35ff3dc9a5 71 }
pshabbaki3 0:5d35ff3dc9a5 72 }
pshabbaki3 0:5d35ff3dc9a5 73 }
pshabbaki3 0:5d35ff3dc9a5 74
pshabbaki3 0:5d35ff3dc9a5 75
pshabbaki3 0:5d35ff3dc9a5 76
pshabbaki3 0:5d35ff3dc9a5 77 int main()
pshabbaki3 0:5d35ff3dc9a5 78 {
pshabbaki3 0:5d35ff3dc9a5 79 load_from_file();
pshabbaki3 0:5d35ff3dc9a5 80
pshabbaki3 0:5d35ff3dc9a5 81 //interupt driven read from serial port
pshabbaki3 0:5d35ff3dc9a5 82 // calls save_to_file();
pshabbaki3 0:5d35ff3dc9a5 83 while(1) {
pshabbaki3 0:5d35ff3dc9a5 84 char c = pc.getc();
pshabbaki3 0:5d35ff3dc9a5 85 if (c!='#') {
pshabbaki3 0:5d35ff3dc9a5 86 im.push_back(c); //writing all the characters into vector
pshabbaki3 0:5d35ff3dc9a5 87 checkKeyboard(c);
pshabbaki3 0:5d35ff3dc9a5 88 } else {
pshabbaki3 0:5d35ff3dc9a5 89 for (int cnt = 0; cnt<im.size(); cnt++) {
pshabbaki3 0:5d35ff3dc9a5 90 pc.printf("%c",im[cnt]);
pshabbaki3 0:5d35ff3dc9a5 91 lcd.printf("%c",im[cnt]);
pshabbaki3 0:5d35ff3dc9a5 92 }
pshabbaki3 0:5d35ff3dc9a5 93 }
pshabbaki3 0:5d35ff3dc9a5 94 }
pshabbaki3 0:5d35ff3dc9a5 95
pshabbaki3 0:5d35ff3dc9a5 96 }
pshabbaki3 0:5d35ff3dc9a5 97
pshabbaki3 0:5d35ff3dc9a5 98