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: FatFileSystemSD mbed
Diff: main.cpp
- Revision:
- 0:7e4786a3584b
diff -r 000000000000 -r 7e4786a3584b main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Oct 11 20:49:25 2012 +0000
@@ -0,0 +1,474 @@
+# include <mbed.h>
+#include <mpr121.h>
+#include <string>
+#include <list>
+#include <mpr121.h>
+#include "TextLCD.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <sstream>
+#include <iostream>
+#include "ID12RFID.h"
+#include "Camera_LS_Y201.h"
+#include "SDFileSystem.h"
+
+
+
+TextLCD lcd(p15, p16, p17, p18, p19, p20);
+//ID12RFID rfid(p14);
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+bool test1 = false;
+bool test2 = false;
+//int a=0;
+int counter1=0;
+int Code[4]= {0,0,0,0};
+int Code2[4];
+int flag=0;
+int a=0;
+int b=0;
+int enter=0;
+int end=0;
+int c=0;
+int chk1=0;
+int a1=0;
+int r=0;
+InterruptIn interrupt(p26);
+// Setup the i2c bus on pins 9 and 10
+I2C i2c(p9, p10);
+// Setup the Mpr121:
+// constructor(i2c object, i2c address of the mpr121)
+Mpr121 mpr121(&i2c, Mpr121::ADD_VSS);
+ID12RFID rfid(p14); // uart rx
+
+
+
+
+#define USE_SDCARD 1
+
+#if USE_SDCARD
+#define FILENAME "/sd/IMG_%04d.jpg"
+SDFileSystem fs(p5, p6, p7, p8, "sd");
+#else
+#define FILENAME "/local/IMG_%04d.jpg"
+LocalFileSystem fs("local");
+#endif
+Camera_LS_Y201 cam1(p28, p27);
+typedef struct work {
+ FILE *fp;
+} work_t;
+
+work_t work;
+
+/**
+ * Callback function for readJpegFileContent.
+ *
+ * @param buf A pointer to a buffer.
+ * @param siz A size of the buffer.
+ */
+void callback_func(int done, int total, uint8_t *buf, size_t siz) {
+ fwrite(buf, siz, 1, work.fp);
+
+ static int n = 0;
+ int tmp = done * 100 / total;
+ if (n != tmp) {
+ n = tmp;
+ lcd.cls();
+ lcd.printf("Writing...: %3d%%", n);
+ //wait(3);
+ // ////newline();
+ }
+}
+
+/**
+ * Capture.
+ *
+ * @param cam A pointer to a camera object.
+ * @param filename The file name.
+ *
+ * @return Return 0 if it succeed.
+ */
+int capture(Camera_LS_Y201 *cam, char *filename) {
+ /*
+ * Take a picture.
+ */
+ if (cam->takePicture() != 0) {
+ return -1;
+ }
+ lcd.cls();
+ lcd.printf("Captured.");
+ wait(3);
+ // //newline();
+
+ /*
+ * Open file.
+ */
+
+ work.fp = fopen(filename, "wb");
+ if (work.fp == NULL) {
+ return -2;
+ }
+
+ /*
+ * Read the content.
+ */
+ lcd.printf("%s", filename);
+ wait(3);
+ ////newline();
+ if (cam->readJpegFileContent(callback_func) != 0) {
+ fclose(work.fp);
+ return -3;
+ }
+ fclose(work.fp);
+
+ /*
+ * Stop taking pictures.
+ */
+ cam->stopTakingPictures();
+
+ return 0;
+}
+//DigitalOut led1(LED1);
+
+//TextLCD lcd(p15, p16, p17, p18, p19, p20); // rs, e, d4-d7
+// Key hit/release interrupt routine
+void fallInterrupt() {
+ int key_code=0;
+ int i=0;
+ int value=mpr121.read(0x00);
+ value +=mpr121.read(0x01)<<8;
+ // LED demo mod
+ i=0;
+ // puts key number out to LEDs for demo
+ for (i=0; i<12; i++) {
+ if (((value>>i)&0x01)==1)
+ {
+// led4=0;
+ b=1;
+
+ key_code=i+1;
+ if(key_code==12)
+ {
+ end=1;
+ c=0;
+ }
+ else if(key_code==11)
+ {
+ enter=1;
+ c=0;
+ }
+ else
+ {
+ //a=i;
+ if(counter1 < 4)
+ {
+ Code[counter1] = i;
+ counter1++;
+ }
+ if(counter1==4)
+ {
+ Code2[0]=Code[0];
+ Code2[1]=Code[1];
+ Code2[2]=Code[2];
+ Code2[3]=Code[3];
+ Code[0]=0;
+ Code[1]=0;
+ Code[2]=0;
+ Code[3]=0;
+ counter1=0; }
+ c++;
+ }
+
+ /* led4=key_code & 0x01;
+ led3=(key_code>>1) & 0x01;
+ led2=(key_code>>2) & 0x01;
+ led1=(key_code>>3) & 0x01;*/
+ led4=1;
+
+}
+//if(led4)
+//led4=0;
+}
+}
+int main()
+{
+ interrupt.fall(&fallInterrupt);
+ interrupt.mode(PullUp);
+
+ while(1) {
+ //Code[4]={0,0,0,0};
+ lcd.cls();
+ lcd.printf("Welcome to Chase Bank");
+ wait(4);
+ lcd.cls();
+ lcd.printf("Please tap your card");
+ wait(3);
+ if(rfid.readable()) {
+ lcd.cls();
+ a=rfid.read();
+ a1=a;
+ lcd.printf("RFID Tag number : %d\n", a);
+ wait(3);
+ led1=1;
+ } else {
+ lcd.cls();
+ lcd.printf("card not read properly");
+ wait(3);
+ a=0;
+ }
+ if(a==36905538 || a==36910393) {
+ test1=true;
+ lcd.cls();
+ lcd.printf("Valid Card detected\n");
+ wait(3);
+ lcd.printf("Card ID:- %d",a);
+ wait(3);
+ lcd.cls();
+ lcd.printf("Level 1 cleared");
+ wait(2);
+ lcd.cls();
+ lcd.printf("test1--%d",test1);
+ wait(2);
+ }
+ if(test1 && a!=0) {
+ lcd.cls();
+ lcd.printf("Enter 4 digit pin code");
+ wait(10);
+ if(b==1) {
+ //lcd.cls();
+ if(c==1)
+ {
+ lcd.cls();
+ lcd.printf("one key pressed");
+ wait(2);
+ }
+ else if(c==2)
+ {
+ lcd.cls();
+ lcd.printf("second key pressed");
+ wait(2);
+ }
+ else if(c==3)
+ {
+ lcd.cls();
+ lcd.printf("third key pressed");
+ wait(2);
+ }
+ else if(c==4)
+ {
+ lcd.cls();
+ lcd.printf("fourth key pressed");
+ wait(2);
+ lcd.cls();
+ lcd.printf("press enter to submit");
+ wait(3);
+ }
+ if(enter)
+ {
+ lcd.cls();
+ lcd.printf("checking");
+ wait(2);
+ /*lcd.printf("%d",Code2[3]);
+ wait(3);
+ lcd.printf("a=",a1);
+ wait(2);*/
+ if(a1==36905538)
+ chk1=40;
+ else if (a1==36910393)
+ chk1=41;
+
+ if(chk1==40)
+ {
+
+ if(Code2[0]==1 && Code2[1]==2 && Code2[2]==3 && Code2[3]==4) {
+ lcd.cls();
+ lcd.printf("PINCODE ACCEPTED");
+ wait(5);
+ test2=true;
+ lcd.cls();
+ lcd.printf("LEVEL 2 Cleared");
+ wait(3);
+ lcd.cls();
+ lcd.printf("Welcome MR. Db");
+ wait(4);
+ lcd.cls();
+ lcd.printf("your amount is 125$");
+ wait(3);
+ //break;
+ } else {
+ lcd.cls();
+ lcd.printf("Intruder Alert");
+ wait(5);
+ ////////////////////start of capture
+ lcd.cls();
+ lcd.printf("Camera module");
+ wait(1);
+ //newline();
+ lcd.cls();
+ lcd.printf("Resetting...");
+ wait(1);
+ //newline();
+ wait(1);
+
+ if (cam1.reset() == 0) {
+ lcd.cls();
+ lcd.printf("Reset OK.");
+ wait(1);
+ //////newline();
+ } else {
+ lcd.cls();
+ lcd.printf("Reset fail.");
+ wait(2);
+ ////////newline();
+ error("Reset fail.");
+ }
+ wait(1);
+
+ int cnt = 0;
+
+ char fname[64];
+ snprintf(fname, sizeof(fname) - 1, FILENAME, cnt);
+ int r = capture(&cam1, fname);
+ if (r == 0) {
+ lcd.cls();
+ lcd.printf("[%04d]:OK.", cnt);
+ ////newline();
+ led1=1;
+ } else {
+ lcd.cls();
+ lcd.printf("[%04d]:NG. (code=%d)", cnt, r);
+ ////newline();
+ error("Failure.");
+ led2=1;
+ }
+ cnt++;
+ ////////////////end of capture
+ while(r!=10)
+ {
+ if(r%2!=0)
+ {
+ led1=1;
+ led2=0;
+ led3=1;
+ led4=0;
+ }
+ if(r%2==0)
+ {
+ led1=0;
+ led2=1;
+ led3=0;
+ led4=1;
+ }
+
+ r++;
+ wait(1);
+ }
+ if(r==10)
+ r=0;
+ // } break;
+ }
+ }
+ else if(chk1==41)
+ {
+ if(Code2[0]==5 && Code2[1]==6 && Code2[2]==7 && Code2[3]==8) {
+ lcd.cls();
+ lcd.printf("PINCODE ACCEPTED");
+ wait(5);
+ test2=true;
+ lcd.printf("LEVEL 2 Cleared");
+ wait(3);
+ lcd.cls();
+ lcd.printf("Welcome MR. Db");
+ wait(4);
+ lcd.printf("your amount is 125$");
+ wait(3);
+ //break;
+ } else {
+ lcd.cls();
+ lcd.printf("Intruder Alert");
+ wait(5);
+ ////////start of capture
+ lcd.cls();
+ lcd.printf("Camera module");
+ //newline();
+ lcd.cls();
+ lcd.printf("Resetting...");
+ //newline();
+ wait(1);
+
+ if (cam1.reset() == 0) {
+
+ lcd.cls();
+ lcd.printf("Reset OK.");
+ wait(2);////newline();
+ } else {
+ lcd.cls();
+ lcd.printf("Reset fail.");
+ wait(2);////newline();
+ error("Reset fail.");
+ }
+ wait(1);
+
+ int cnt = 0;
+ char fname[64];
+ snprintf(fname, sizeof(fname) - 1, FILENAME, cnt);
+ int r = capture(&cam1, fname);
+ if (r == 0) {
+ lcd.cls();
+ lcd.printf("[%04d]:OK.", cnt);
+ wait(2);////newline();
+ led1=1;
+ } else {
+ lcd.cls();
+ lcd.printf("[%04d]:NG. (code=%d)", cnt, r);
+ wait(2);////newline();
+ error("Failure.");
+ led2=1;
+ }
+ cnt++;
+ /////////////end of capture
+
+ while(r!=10)
+ {
+ if(r%2!=0)
+ {
+ led1=1;
+ led2=0;
+ led3=1;
+ led4=0;
+ }
+ if(r%2==0)
+ {
+ led1=0;
+ led2=1;
+ led3=0;
+ led4=1;
+ }
+
+ r++;
+ wait(1);
+ }
+ if(r==10)
+ r=0;
+ //break;
+ }
+ }
+
+ enter=0;
+ } //end of enter
+ else if(end)
+ {
+ lcd.cls();
+ lcd.printf("ending");
+ wait(3);
+ end=0;
+ } //end of end
+ }//end of b==1
+
+
+ }
+ }
+
+ }
\ No newline at end of file