4180 Final Project

Dependencies:   4DGL-uLCD-SE mbed Servo

Committer:
ecarrick
Date:
Tue Apr 12 15:40:19 2016 +0000
Revision:
1:dd048edb2716
Parent:
0:5d35ff3dc9a5
Child:
3:babc3bec33ca
adding local file system

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