![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
A simple digital lock with attempted audio guidance
Dependencies: FATFileSystem TextLCD mbed
Fork of Digital_Lock_with_audio by
main.cpp@2:9bdba6204bb4, 2013-05-11 (annotated)
- Committer:
- kit2
- Date:
- Sat May 11 12:00:13 2013 +0000
- Revision:
- 2:9bdba6204bb4
- Parent:
- 1:85eb1c94154a
- Child:
- 4:74d697416c75
A digital lock with touch panel as input and LCD for instruction display. Attempted audio guidance for the user
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kit2 | 2:9bdba6204bb4 | 1 | /* Digital Lock System |
kit2 | 2:9bdba6204bb4 | 2 | Components Used: |
kit2 | 2:9bdba6204bb4 | 3 | NGX Baseboord |
kit2 | 2:9bdba6204bb4 | 4 | MPR121 Capacitive touch panel as keypad( p26, p9, p10)// IRQ, SDA, SCL |
kit2 | 2:9bdba6204bb4 | 5 | LCD for display(p24, p25, p27, p28, p29, p30) // rs, e, d4-d7 |
kit2 | 2:9bdba6204bb4 | 6 | Motor for opening/closing the lock(p11, p12) // for input in H Bridge |
kit2 | 2:9bdba6204bb4 | 7 | Baseboard SD Card for storing Forest.wav |
kit2 | 2:9bdba6204bb4 | 8 | Baseboard audio jack 3.5 mm |
4180_1 | 0:e09703934ff4 | 9 | |
kit2 | 2:9bdba6204bb4 | 10 | By using touch panel as input we enter the desired password to open the lock. |
kit2 | 2:9bdba6204bb4 | 11 | Initially we store a password in array ORG[] which can be compared with the password(length= 7)entered by the user. |
kit2 | 2:9bdba6204bb4 | 12 | |
kit2 | 2:9bdba6204bb4 | 13 | If the entered password is correct then motor opens the door. |
kit2 | 2:9bdba6204bb4 | 14 | In case of wrong password the user is asked to re-enter the password. 3 trials are given after which door is permanently |
kit2 | 2:9bdba6204bb4 | 15 | locked. |
kit2 | 2:9bdba6204bb4 | 16 | Option to change the password is also provided. |
kit2 | 2:9bdba6204bb4 | 17 | The process is guided by display of instruction on the LCD. |
kit2 | 2:9bdba6204bb4 | 18 | |
kit2 | 2:9bdba6204bb4 | 19 | |
kit2 | 2:9bdba6204bb4 | 20 | Under Progress: |
kit2 | 2:9bdba6204bb4 | 21 | An attempt is being made to guide the user by playing relavent audio files along with the instructions on LCD. |
kit2 | 2:9bdba6204bb4 | 22 | The "forest.wav" file is the one that we are attempting to play along with LCD instructions. |
kit2 | 2:9bdba6204bb4 | 23 | the bit rate of the wave file is 176kbps. |
kit2 | 2:9bdba6204bb4 | 24 | */ |
kit2 | 1:85eb1c94154a | 25 | |
4180_1 | 0:e09703934ff4 | 26 | |
4180_1 | 0:e09703934ff4 | 27 | |
kit2 | 1:85eb1c94154a | 28 | #include "mbed.h" |
kit2 | 1:85eb1c94154a | 29 | #include "SDFileSystem.h" |
4180_1 | 0:e09703934ff4 | 30 | #include <string> |
4180_1 | 0:e09703934ff4 | 31 | #include <list> |
kit2 | 1:85eb1c94154a | 32 | #include <mpr121.h> |
kit2 | 1:85eb1c94154a | 33 | #include "TextLCD.h" |
kit2 | 1:85eb1c94154a | 34 | #include <stdio.h> |
kit2 | 1:85eb1c94154a | 35 | #include <stdlib.h> |
kit2 | 1:85eb1c94154a | 36 | #include <sstream> |
kit2 | 1:85eb1c94154a | 37 | #include <iostream> |
4180_1 | 0:e09703934ff4 | 38 | |
kit2 | 1:85eb1c94154a | 39 | |
kit2 | 1:85eb1c94154a | 40 | //------------------------------------------------------------------initialize lcd |
4180_1 | 0:e09703934ff4 | 41 | |
kit2 | 1:85eb1c94154a | 42 | TextLCD lcd(p24, p25, p27, p28, p29, p30); // rs, e, d4-d7 |
kit2 | 1:85eb1c94154a | 43 | //-------------------------------------------------------------------- |
kit2 | 1:85eb1c94154a | 44 | |
kit2 | 1:85eb1c94154a | 45 | //------------------------------------------------------------------initial touch pannel |
4180_1 | 0:e09703934ff4 | 46 | DigitalOut led1(LED1); |
4180_1 | 0:e09703934ff4 | 47 | DigitalOut led2(LED2); |
4180_1 | 0:e09703934ff4 | 48 | DigitalOut led3(LED3); |
4180_1 | 0:e09703934ff4 | 49 | DigitalOut led4(LED4); |
kit2 | 1:85eb1c94154a | 50 | DigitalOut servo(p12); |
kit2 | 1:85eb1c94154a | 51 | int org[7] = {0,0,0,0,0,0,0}; |
kit2 | 1:85eb1c94154a | 52 | int Nums[7] = {0,0,0,0,0,0,0}; |
kit2 | 1:85eb1c94154a | 53 | int counter = 0; |
kit2 | 1:85eb1c94154a | 54 | int count2 = 0; |
kit2 | 2:9bdba6204bb4 | 55 | int k=0; |
kit2 | 2:9bdba6204bb4 | 56 | DigitalOut myled(p11); |
kit2 | 2:9bdba6204bb4 | 57 | DigitalOut myled1(p12); |
kit2 | 1:85eb1c94154a | 58 | //------------------------------------------- Create the interrupt receiver object on pin 26 |
4180_1 | 0:e09703934ff4 | 59 | InterruptIn interrupt(p26); |
kit2 | 1:85eb1c94154a | 60 | |
4180_1 | 0:e09703934ff4 | 61 | |
kit2 | 1:85eb1c94154a | 62 | //-------------------------------------------------------- Setup the i2c bus on pins 28 and 27 |
kit2 | 1:85eb1c94154a | 63 | I2C i2c(p9, p10); |
kit2 | 1:85eb1c94154a | 64 | |
4180_1 | 0:e09703934ff4 | 65 | |
kit2 | 1:85eb1c94154a | 66 | //------------------------------------------ constructor(i2c object, i2c address of the mpr121) |
4180_1 | 0:e09703934ff4 | 67 | Mpr121 mpr121(&i2c, Mpr121::ADD_VSS); |
4180_1 | 0:e09703934ff4 | 68 | |
kit2 | 1:85eb1c94154a | 69 | //-------------------------------------------------------------------touch panel initialised |
kit2 | 1:85eb1c94154a | 70 | |
kit2 | 1:85eb1c94154a | 71 | |
kit2 | 1:85eb1c94154a | 72 | |
kit2 | 1:85eb1c94154a | 73 | //---------------------------------------------------------------------------------------------playing audio |
kit2 | 1:85eb1c94154a | 74 | AnalogOut DACout(p18); |
kit2 | 1:85eb1c94154a | 75 | DigitalOut digout(LED4); |
kit2 | 1:85eb1c94154a | 76 | Ticker tick; |
kit2 | 1:85eb1c94154a | 77 | SDFileSystem sd(p5, p6, p7, p8, "sd"); // NGX mbed base board |
kit2 | 1:85eb1c94154a | 78 | |
kit2 | 1:85eb1c94154a | 79 | #define SAMPLE_FREQ 40000 |
kit2 | 1:85eb1c94154a | 80 | #define BUF_SIZE (SAMPLE_FREQ/10) |
kit2 | 1:85eb1c94154a | 81 | #define SLICE_BUF_SIZE 1 |
kit2 | 1:85eb1c94154a | 82 | |
kit2 | 1:85eb1c94154a | 83 | void dac_out(void); |
kit2 | 1:85eb1c94154a | 84 | void play_wave(char *); |
kit2 | 1:85eb1c94154a | 85 | void cleanup(char *); |
kit2 | 1:85eb1c94154a | 86 | void fill_adc_buf(short *, unsigned); |
kit2 | 1:85eb1c94154a | 87 | void swapword(unsigned *); |
kit2 | 1:85eb1c94154a | 88 | |
kit2 | 1:85eb1c94154a | 89 | // a FIFO for the DAC |
kit2 | 1:85eb1c94154a | 90 | short DAC_fifo[256]; |
kit2 | 1:85eb1c94154a | 91 | short DAC_wptr; |
kit2 | 1:85eb1c94154a | 92 | short DAC_rptr; |
kit2 | 1:85eb1c94154a | 93 | short DAC_on; |
kit2 | 1:85eb1c94154a | 94 | |
kit2 | 1:85eb1c94154a | 95 | typedef struct uFMT_STRUCT { |
kit2 | 1:85eb1c94154a | 96 | short comp_code; |
kit2 | 1:85eb1c94154a | 97 | short num_channels; |
kit2 | 1:85eb1c94154a | 98 | unsigned sample_rate; |
kit2 | 1:85eb1c94154a | 99 | unsigned avg_Bps; |
kit2 | 1:85eb1c94154a | 100 | short block_align; |
kit2 | 1:85eb1c94154a | 101 | short sig_bps; |
kit2 | 1:85eb1c94154a | 102 | } FMT_STRUCT; |
kit2 | 1:85eb1c94154a | 103 | void play_wave(char *wavname) |
kit2 | 1:85eb1c94154a | 104 | { |
kit2 | 1:85eb1c94154a | 105 | unsigned chunk_id,chunk_size,channel; |
kit2 | 1:85eb1c94154a | 106 | // unsigned *data_wptr,data,samp_int,i; |
kit2 | 1:85eb1c94154a | 107 | unsigned data,samp_int,i; |
kit2 | 1:85eb1c94154a | 108 | short dac_data; |
kit2 | 1:85eb1c94154a | 109 | char *slice_buf; |
kit2 | 1:85eb1c94154a | 110 | short *data_sptr; |
kit2 | 1:85eb1c94154a | 111 | // char *data_bptr; |
kit2 | 1:85eb1c94154a | 112 | FMT_STRUCT wav_format; |
kit2 | 1:85eb1c94154a | 113 | FILE *wavfile; |
kit2 | 1:85eb1c94154a | 114 | long slice,num_slices; |
kit2 | 1:85eb1c94154a | 115 | DAC_wptr=0; |
kit2 | 1:85eb1c94154a | 116 | DAC_rptr=0; |
kit2 | 1:85eb1c94154a | 117 | for (i=0;i<256;i+=2) |
kit2 | 1:85eb1c94154a | 118 | { |
kit2 | 1:85eb1c94154a | 119 | DAC_fifo[i]=0; |
kit2 | 1:85eb1c94154a | 120 | DAC_fifo[i+1]=3000; |
kit2 | 1:85eb1c94154a | 121 | } |
kit2 | 1:85eb1c94154a | 122 | DAC_wptr=4; |
kit2 | 1:85eb1c94154a | 123 | DAC_on=0; |
kit2 | 1:85eb1c94154a | 124 | |
kit2 | 1:85eb1c94154a | 125 | led1=led2=led3=led4=0; |
kit2 | 1:85eb1c94154a | 126 | |
kit2 | 1:85eb1c94154a | 127 | wavfile=fopen(wavname,"rb"); |
kit2 | 1:85eb1c94154a | 128 | if (!wavfile) { |
kit2 | 1:85eb1c94154a | 129 | printf("Unable to open wav file '%s'\n",wavname); |
kit2 | 1:85eb1c94154a | 130 | exit(1); |
kit2 | 1:85eb1c94154a | 131 | } |
kit2 | 1:85eb1c94154a | 132 | |
kit2 | 1:85eb1c94154a | 133 | fread(&chunk_id,4,1,wavfile); |
kit2 | 1:85eb1c94154a | 134 | fread(&chunk_size,4,1,wavfile); |
kit2 | 1:85eb1c94154a | 135 | while (!feof(wavfile)) { |
kit2 | 1:85eb1c94154a | 136 | switch (chunk_id) { |
kit2 | 1:85eb1c94154a | 137 | case 0x46464952: |
kit2 | 1:85eb1c94154a | 138 | fread(&data,4,1,wavfile); |
kit2 | 1:85eb1c94154a | 139 | break; |
kit2 | 1:85eb1c94154a | 140 | case 0x20746d66: |
kit2 | 1:85eb1c94154a | 141 | fread(&wav_format,sizeof(wav_format),1,wavfile); |
kit2 | 1:85eb1c94154a | 142 | if (chunk_size > sizeof(wav_format)) |
kit2 | 1:85eb1c94154a | 143 | fseek(wavfile,chunk_size-sizeof(wav_format),SEEK_CUR); |
kit2 | 1:85eb1c94154a | 144 | // create a slice buffer large enough to hold multiple slices |
kit2 | 1:85eb1c94154a | 145 | slice_buf=(char *)malloc(wav_format.block_align*SLICE_BUF_SIZE); |
kit2 | 1:85eb1c94154a | 146 | if (!slice_buf) { |
kit2 | 1:85eb1c94154a | 147 | exit(1); |
kit2 | 1:85eb1c94154a | 148 | } |
kit2 | 1:85eb1c94154a | 149 | break; |
kit2 | 1:85eb1c94154a | 150 | case 0x61746164: |
kit2 | 1:85eb1c94154a | 151 | slice_buf=(char *)malloc(wav_format.block_align*SLICE_BUF_SIZE); |
kit2 | 1:85eb1c94154a | 152 | if (!slice_buf) { |
kit2 | 1:85eb1c94154a | 153 | exit(1); |
kit2 | 1:85eb1c94154a | 154 | } num_slices=chunk_size/wav_format.block_align; |
kit2 | 1:85eb1c94154a | 155 | samp_int=1000000/(wav_format.sample_rate); |
kit2 | 1:85eb1c94154a | 156 | |
kit2 | 1:85eb1c94154a | 157 | // starting up ticker to write samples out -- no printfs until tick.detach is called |
kit2 | 1:85eb1c94154a | 158 | tick.attach_us(&dac_out, samp_int); |
kit2 | 1:85eb1c94154a | 159 | DAC_on=1; |
kit2 | 1:85eb1c94154a | 160 | led2=1; |
kit2 | 1:85eb1c94154a | 161 | for (slice=0;slice<num_slices;slice+=SLICE_BUF_SIZE) { |
kit2 | 1:85eb1c94154a | 162 | fread(slice_buf,wav_format.block_align*SLICE_BUF_SIZE,1,wavfile); |
kit2 | 1:85eb1c94154a | 163 | if (feof(wavfile)) { |
kit2 | 1:85eb1c94154a | 164 | exit(1); |
kit2 | 1:85eb1c94154a | 165 | } |
kit2 | 1:85eb1c94154a | 166 | data_sptr=(short *)slice_buf; |
kit2 | 1:85eb1c94154a | 167 | for (i=0;i<SLICE_BUF_SIZE;i++) { |
kit2 | 1:85eb1c94154a | 168 | dac_data=0; |
kit2 | 1:85eb1c94154a | 169 | |
kit2 | 1:85eb1c94154a | 170 | // for a stereo wave file average the two channels. |
kit2 | 1:85eb1c94154a | 171 | for (channel=0;channel<wav_format.num_channels;channel++) { |
kit2 | 1:85eb1c94154a | 172 | switch (wav_format.sig_bps) { |
kit2 | 1:85eb1c94154a | 173 | case 16: |
kit2 | 1:85eb1c94154a | 174 | dac_data+=( ((int)(*data_sptr++)) +32768)>>5; |
kit2 | 1:85eb1c94154a | 175 | break; |
kit2 | 1:85eb1c94154a | 176 | } |
kit2 | 1:85eb1c94154a | 177 | } |
kit2 | 1:85eb1c94154a | 178 | dac_data>>=1; |
kit2 | 1:85eb1c94154a | 179 | DAC_fifo[DAC_wptr]=dac_data; |
kit2 | 1:85eb1c94154a | 180 | DAC_wptr=(DAC_wptr+1) & 0xff; |
kit2 | 1:85eb1c94154a | 181 | while (DAC_wptr==DAC_rptr) { |
kit2 | 1:85eb1c94154a | 182 | led1=1; |
kit2 | 1:85eb1c94154a | 183 | } |
kit2 | 1:85eb1c94154a | 184 | led1=0; |
kit2 | 1:85eb1c94154a | 185 | } |
kit2 | 1:85eb1c94154a | 186 | } |
kit2 | 1:85eb1c94154a | 187 | DAC_on=0; |
kit2 | 1:85eb1c94154a | 188 | led2=0; |
kit2 | 1:85eb1c94154a | 189 | tick.detach(); |
kit2 | 1:85eb1c94154a | 190 | led3=1; |
kit2 | 1:85eb1c94154a | 191 | free(slice_buf); |
kit2 | 1:85eb1c94154a | 192 | break; |
kit2 | 1:85eb1c94154a | 193 | case 0x5453494c: |
kit2 | 1:85eb1c94154a | 194 | fseek(wavfile,chunk_size,SEEK_CUR); |
kit2 | 1:85eb1c94154a | 195 | break; |
kit2 | 1:85eb1c94154a | 196 | default: |
kit2 | 1:85eb1c94154a | 197 | data=fseek(wavfile,chunk_size,SEEK_CUR); |
kit2 | 1:85eb1c94154a | 198 | break; |
kit2 | 1:85eb1c94154a | 199 | } |
kit2 | 1:85eb1c94154a | 200 | fread(&chunk_id,4,1,wavfile); |
kit2 | 1:85eb1c94154a | 201 | fread(&chunk_size,4,1,wavfile); |
kit2 | 1:85eb1c94154a | 202 | } |
kit2 | 1:85eb1c94154a | 203 | fclose(wavfile); |
kit2 | 1:85eb1c94154a | 204 | led1=0; |
kit2 | 1:85eb1c94154a | 205 | } |
kit2 | 1:85eb1c94154a | 206 | |
kit2 | 1:85eb1c94154a | 207 | |
kit2 | 1:85eb1c94154a | 208 | void dac_out() |
kit2 | 1:85eb1c94154a | 209 | { |
kit2 | 1:85eb1c94154a | 210 | if (DAC_on) { |
kit2 | 1:85eb1c94154a | 211 | digout=1; |
kit2 | 1:85eb1c94154a | 212 | DACout.write_u16(DAC_fifo[DAC_rptr]); |
kit2 | 1:85eb1c94154a | 213 | DAC_rptr=(DAC_rptr+1) & 0xff; |
kit2 | 1:85eb1c94154a | 214 | digout=0; |
kit2 | 1:85eb1c94154a | 215 | } |
kit2 | 1:85eb1c94154a | 216 | } |
kit2 | 1:85eb1c94154a | 217 | |
kit2 | 1:85eb1c94154a | 218 | |
kit2 | 1:85eb1c94154a | 219 | |
kit2 | 1:85eb1c94154a | 220 | |
kit2 | 1:85eb1c94154a | 221 | //--------------------------------------------------------------------------------------------- |
kit2 | 1:85eb1c94154a | 222 | |
kit2 | 1:85eb1c94154a | 223 | //-------------------------------------------------------------------------------obtaining input |
kit2 | 1:85eb1c94154a | 224 | |
kit2 | 2:9bdba6204bb4 | 225 | |
4180_1 | 0:e09703934ff4 | 226 | void fallInterrupt() { |
kit2 | 1:85eb1c94154a | 227 | int key_code=0; |
4180_1 | 0:e09703934ff4 | 228 | int i=0; |
4180_1 | 0:e09703934ff4 | 229 | int value=mpr121.read(0x00); |
4180_1 | 0:e09703934ff4 | 230 | value +=mpr121.read(0x01)<<8; |
kit2 | 1:85eb1c94154a | 231 | |
4180_1 | 0:e09703934ff4 | 232 | i=0; |
4180_1 | 0:e09703934ff4 | 233 | // puts key number out to LEDs for demo |
kit2 | 1:85eb1c94154a | 234 | for (i=0; i<12; i++) |
kit2 | 1:85eb1c94154a | 235 | { |
kit2 | 1:85eb1c94154a | 236 | if (((value>>i)&0x01)==1) |
kit2 | 2:9bdba6204bb4 | 237 | { |
kit2 | 2:9bdba6204bb4 | 238 | if(counter==0) |
kit2 | 2:9bdba6204bb4 | 239 | { |
kit2 | 2:9bdba6204bb4 | 240 | lcd.cls(); |
kit2 | 2:9bdba6204bb4 | 241 | lcd.printf(""); |
kit2 | 2:9bdba6204bb4 | 242 | } |
kit2 | 1:85eb1c94154a | 243 | key_code=i; |
kit2 | 1:85eb1c94154a | 244 | lcd.printf("%d", i); |
kit2 | 1:85eb1c94154a | 245 | if(counter < 7) |
kit2 | 1:85eb1c94154a | 246 | { |
kit2 | 2:9bdba6204bb4 | 247 | |
kit2 | 1:85eb1c94154a | 248 | Nums[counter] = i; |
kit2 | 1:85eb1c94154a | 249 | counter++; |
kit2 | 1:85eb1c94154a | 250 | } |
4180_1 | 0:e09703934ff4 | 251 | } |
kit2 | 1:85eb1c94154a | 252 | } |
4180_1 | 0:e09703934ff4 | 253 | led4=key_code & 0x01; |
4180_1 | 0:e09703934ff4 | 254 | led3=(key_code>>1) & 0x01; |
4180_1 | 0:e09703934ff4 | 255 | led2=(key_code>>2) & 0x01; |
4180_1 | 0:e09703934ff4 | 256 | led1=(key_code>>3) & 0x01; |
4180_1 | 0:e09703934ff4 | 257 | } |
kit2 | 1:85eb1c94154a | 258 | |
4180_1 | 0:e09703934ff4 | 259 | |
kit2 | 1:85eb1c94154a | 260 | //------------------------------------------------------------------------------MAIN |
4180_1 | 0:e09703934ff4 | 261 | |
4180_1 | 0:e09703934ff4 | 262 | |
kit2 | 1:85eb1c94154a | 263 | int main() |
kit2 | 1:85eb1c94154a | 264 | { |
4180_1 | 0:e09703934ff4 | 265 | |
kit2 | 1:85eb1c94154a | 266 | //------------------------------------------------to start enter new password which user wants to set |
kit2 | 1:85eb1c94154a | 267 | lcd.cls(); |
kit2 | 1:85eb1c94154a | 268 | lcd.printf("enter your new password\n"); |
kit2 | 1:85eb1c94154a | 269 | play_wave("/sd/forest.wav"); |
kit2 | 1:85eb1c94154a | 270 | wait(0.5); |
4180_1 | 0:e09703934ff4 | 271 | |
kit2 | 1:85eb1c94154a | 272 | int k; |
kit2 | 1:85eb1c94154a | 273 | //----------------------------------------------enter password |
kit2 | 1:85eb1c94154a | 274 | while(1) |
kit2 | 1:85eb1c94154a | 275 | { |
kit2 | 1:85eb1c94154a | 276 | interrupt.fall(&fallInterrupt); |
kit2 | 1:85eb1c94154a | 277 | interrupt.mode(PullUp); |
kit2 | 1:85eb1c94154a | 278 | if(counter==7){ |
kit2 | 1:85eb1c94154a | 279 | break;} |
4180_1 | 0:e09703934ff4 | 280 | } |
kit2 | 1:85eb1c94154a | 281 | |
kit2 | 1:85eb1c94154a | 282 | |
kit2 | 1:85eb1c94154a | 283 | for (k=0; k<7; k++) |
kit2 | 1:85eb1c94154a | 284 | { |
kit2 | 1:85eb1c94154a | 285 | org[k]=Nums[k]; |
kit2 | 1:85eb1c94154a | 286 | } |
kit2 | 1:85eb1c94154a | 287 | |
kit2 | 1:85eb1c94154a | 288 | wait(1); |
kit2 | 1:85eb1c94154a | 289 | |
kit2 | 1:85eb1c94154a | 290 | AGAIN: |
kit2 | 1:85eb1c94154a | 291 | lcd.cls(); |
kit2 | 1:85eb1c94154a | 292 | lcd.printf("1-open door\n2-reset password"); |
kit2 | 2:9bdba6204bb4 | 293 | //play_wave("/sd/forest.wav"); |
4180_1 | 0:e09703934ff4 | 294 | interrupt.fall(&fallInterrupt); |
4180_1 | 0:e09703934ff4 | 295 | interrupt.mode(PullUp); |
kit2 | 1:85eb1c94154a | 296 | |
kit2 | 1:85eb1c94154a | 297 | while (1) |
kit2 | 1:85eb1c94154a | 298 | { |
kit2 | 1:85eb1c94154a | 299 | counter=0; |
kit2 | 1:85eb1c94154a | 300 | if(Nums[0]==1) |
kit2 | 1:85eb1c94154a | 301 | { |
kit2 | 1:85eb1c94154a | 302 | lcd.cls(); |
kit2 | 1:85eb1c94154a | 303 | //---------------------------------------------------enter the password |
kit2 | 1:85eb1c94154a | 304 | lcd.printf("enter your password\n"); |
kit2 | 2:9bdba6204bb4 | 305 | //play_wave("/sd/forest.wav"); |
kit2 | 1:85eb1c94154a | 306 | wait(1); |
kit2 | 1:85eb1c94154a | 307 | |
kit2 | 1:85eb1c94154a | 308 | while(1) |
kit2 | 1:85eb1c94154a | 309 | { |
kit2 | 1:85eb1c94154a | 310 | interrupt.fall(&fallInterrupt); |
kit2 | 1:85eb1c94154a | 311 | interrupt.mode(PullUp); |
kit2 | 1:85eb1c94154a | 312 | if(counter==7){break;} |
kit2 | 1:85eb1c94154a | 313 | } |
kit2 | 1:85eb1c94154a | 314 | if(counter == 7) |
kit2 | 1:85eb1c94154a | 315 | { |
kit2 | 1:85eb1c94154a | 316 | wait(1); |
kit2 | 1:85eb1c94154a | 317 | //lcd.printf("%d",Nums[4]); |
kit2 | 1:85eb1c94154a | 318 | for(k=0;k<7;k++) |
kit2 | 1:85eb1c94154a | 319 | { |
kit2 | 1:85eb1c94154a | 320 | lcd.printf("%d",Nums[k]); |
kit2 | 1:85eb1c94154a | 321 | wait(1); |
kit2 | 1:85eb1c94154a | 322 | } |
kit2 | 1:85eb1c94154a | 323 | if((Nums[0] == org[0]) && (Nums[1] == org[1]) && (Nums[2] == org[2])&&(Nums[3] == org[3]) && (Nums[4] == org[4]) &&(Nums[5] == org[5])&& (Nums[6] == org[6])) |
kit2 | 1:85eb1c94154a | 324 | { |
kit2 | 1:85eb1c94154a | 325 | lcd.cls(); |
kit2 | 1:85eb1c94154a | 326 | lcd.printf("password is correct, door open\n"); |
kit2 | 1:85eb1c94154a | 327 | servo=1; |
kit2 | 1:85eb1c94154a | 328 | wait(1); |
kit2 | 1:85eb1c94154a | 329 | lcd.cls(); |
kit2 | 1:85eb1c94154a | 330 | lcd.printf("opening door...\n"); |
kit2 | 1:85eb1c94154a | 331 | // play_wave("/sd/forest.wav"); |
kit2 | 2:9bdba6204bb4 | 332 | myled = 1; |
kit2 | 2:9bdba6204bb4 | 333 | myled1 = 0; |
kit2 | 2:9bdba6204bb4 | 334 | wait(5); |
kit2 | 2:9bdba6204bb4 | 335 | myled = 0; |
kit2 | 2:9bdba6204bb4 | 336 | myled1 = 1; |
kit2 | 2:9bdba6204bb4 | 337 | wait(5); |
kit2 | 1:85eb1c94154a | 338 | goto AGAIN; |
kit2 | 1:85eb1c94154a | 339 | } |
kit2 | 1:85eb1c94154a | 340 | else |
kit2 | 1:85eb1c94154a | 341 | { |
kit2 | 2:9bdba6204bb4 | 342 | |
kit2 | 1:85eb1c94154a | 343 | lcd.cls(); |
kit2 | 1:85eb1c94154a | 344 | lcd.printf("password incorrect.retry\n"); |
kit2 | 2:9bdba6204bb4 | 345 | play_wave("/sd/forest.wav"); |
kit2 | 2:9bdba6204bb4 | 346 | wait(10); |
kit2 | 1:85eb1c94154a | 347 | goto AGAIN; |
kit2 | 1:85eb1c94154a | 348 | } |
kit2 | 1:85eb1c94154a | 349 | } |
kit2 | 1:85eb1c94154a | 350 | } |
kit2 | 1:85eb1c94154a | 351 | |
kit2 | 1:85eb1c94154a | 352 | |
kit2 | 1:85eb1c94154a | 353 | wait(1); |
kit2 | 1:85eb1c94154a | 354 | if(Nums[0]==2) |
kit2 | 1:85eb1c94154a | 355 | { |
kit2 | 1:85eb1c94154a | 356 | wait(1); |
kit2 | 1:85eb1c94154a | 357 | counter=0; |
kit2 | 1:85eb1c94154a | 358 | lcd.cls(); |
kit2 | 1:85eb1c94154a | 359 | lcd.printf("enter your old password\n"); |
kit2 | 1:85eb1c94154a | 360 | play_wave("/sd/forest.wav"); |
kit2 | 1:85eb1c94154a | 361 | while(1) |
kit2 | 1:85eb1c94154a | 362 | { |
kit2 | 1:85eb1c94154a | 363 | interrupt.fall(&fallInterrupt); |
kit2 | 1:85eb1c94154a | 364 | interrupt.mode(PullUp); |
kit2 | 1:85eb1c94154a | 365 | if(counter==7){break;} |
kit2 | 1:85eb1c94154a | 366 | } |
kit2 | 1:85eb1c94154a | 367 | |
kit2 | 1:85eb1c94154a | 368 | if(counter == 7) |
kit2 | 1:85eb1c94154a | 369 | { |
kit2 | 1:85eb1c94154a | 370 | |
kit2 | 1:85eb1c94154a | 371 | if((Nums[0] == org[0]) && (Nums[1] == org[1]) && (Nums[2] == org[2])&&(Nums[3] == org[3]) && (Nums[4] == org[4]) &&(Nums[5] == org[5])&& (Nums[6] == org[6])) |
kit2 | 1:85eb1c94154a | 372 | { |
kit2 | 1:85eb1c94154a | 373 | counter=0; |
kit2 | 1:85eb1c94154a | 374 | lcd.cls(); |
kit2 | 1:85eb1c94154a | 375 | lcd.printf("enter your new password"); |
kit2 | 1:85eb1c94154a | 376 | play_wave("/sd/forest.wav"); |
kit2 | 1:85eb1c94154a | 377 | while(1) |
kit2 | 1:85eb1c94154a | 378 | { |
kit2 | 1:85eb1c94154a | 379 | interrupt.fall(&fallInterrupt); |
kit2 | 1:85eb1c94154a | 380 | interrupt.mode(PullUp); |
kit2 | 1:85eb1c94154a | 381 | if(counter==7){break;} |
kit2 | 1:85eb1c94154a | 382 | } |
kit2 | 1:85eb1c94154a | 383 | |
kit2 | 1:85eb1c94154a | 384 | for (k=0; k<7; k++) |
kit2 | 1:85eb1c94154a | 385 | { |
kit2 | 1:85eb1c94154a | 386 | org[k]=Nums[k]; |
kit2 | 1:85eb1c94154a | 387 | } |
kit2 | 1:85eb1c94154a | 388 | |
kit2 | 1:85eb1c94154a | 389 | lcd.cls(); |
kit2 | 1:85eb1c94154a | 390 | lcd.printf("password changed"); |
kit2 | 1:85eb1c94154a | 391 | play_wave("/sd/forest.wav"); |
kit2 | 1:85eb1c94154a | 392 | goto AGAIN; |
kit2 | 1:85eb1c94154a | 393 | } |
kit2 | 1:85eb1c94154a | 394 | else |
kit2 | 1:85eb1c94154a | 395 | { |
kit2 | 1:85eb1c94154a | 396 | lcd.cls(); |
kit2 | 1:85eb1c94154a | 397 | lcd.printf("password incorrect.retry\n"); |
kit2 | 2:9bdba6204bb4 | 398 | k++; |
kit2 | 2:9bdba6204bb4 | 399 | if(k==3) |
kit2 | 2:9bdba6204bb4 | 400 | { |
kit2 | 2:9bdba6204bb4 | 401 | lcd.cls(); |
kit2 | 2:9bdba6204bb4 | 402 | lcd.printf("Locked"); |
kit2 | 2:9bdba6204bb4 | 403 | wait(30); |
kit2 | 2:9bdba6204bb4 | 404 | } |
kit2 | 1:85eb1c94154a | 405 | play_wave("/sd/forest.wav"); |
kit2 | 1:85eb1c94154a | 406 | goto AGAIN; |
kit2 | 1:85eb1c94154a | 407 | } |
kit2 | 1:85eb1c94154a | 408 | } |
4180_1 | 0:e09703934ff4 | 409 | } |
kit2 | 2:9bdba6204bb4 | 410 | else |
kit2 | 2:9bdba6204bb4 | 411 | { |
kit2 | 2:9bdba6204bb4 | 412 | goto AGAIN; |
kit2 | 1:85eb1c94154a | 413 | } |
kit2 | 1:85eb1c94154a | 414 | } |
kit2 | 2:9bdba6204bb4 | 415 | } |