![](/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@1:85eb1c94154a, 2013-04-23 (annotated)
- Committer:
- kit2
- Date:
- Tue Apr 23 12:49:09 2013 +0000
- Revision:
- 1:85eb1c94154a
- Parent:
- 0:e09703934ff4
- Child:
- 2:9bdba6204bb4
digital lock system
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
4180_1 | 0:e09703934ff4 | 1 | |
kit2 | 1:85eb1c94154a | 2 | |
4180_1 | 0:e09703934ff4 | 3 | |
4180_1 | 0:e09703934ff4 | 4 | |
kit2 | 1:85eb1c94154a | 5 | #include "mbed.h" |
kit2 | 1:85eb1c94154a | 6 | #include "SDFileSystem.h" |
4180_1 | 0:e09703934ff4 | 7 | #include <string> |
4180_1 | 0:e09703934ff4 | 8 | #include <list> |
kit2 | 1:85eb1c94154a | 9 | #include <mpr121.h> |
kit2 | 1:85eb1c94154a | 10 | #include "TextLCD.h" |
kit2 | 1:85eb1c94154a | 11 | #include <stdio.h> |
kit2 | 1:85eb1c94154a | 12 | #include <stdlib.h> |
kit2 | 1:85eb1c94154a | 13 | #include <sstream> |
kit2 | 1:85eb1c94154a | 14 | #include <iostream> |
4180_1 | 0:e09703934ff4 | 15 | |
kit2 | 1:85eb1c94154a | 16 | |
kit2 | 1:85eb1c94154a | 17 | //------------------------------------------------------------------initialize lcd |
4180_1 | 0:e09703934ff4 | 18 | |
kit2 | 1:85eb1c94154a | 19 | TextLCD lcd(p24, p25, p27, p28, p29, p30); // rs, e, d4-d7 |
kit2 | 1:85eb1c94154a | 20 | //-------------------------------------------------------------------- |
kit2 | 1:85eb1c94154a | 21 | |
kit2 | 1:85eb1c94154a | 22 | //------------------------------------------------------------------initial touch pannel |
4180_1 | 0:e09703934ff4 | 23 | DigitalOut led1(LED1); |
4180_1 | 0:e09703934ff4 | 24 | DigitalOut led2(LED2); |
4180_1 | 0:e09703934ff4 | 25 | DigitalOut led3(LED3); |
4180_1 | 0:e09703934ff4 | 26 | DigitalOut led4(LED4); |
kit2 | 1:85eb1c94154a | 27 | DigitalOut servo(p12); |
kit2 | 1:85eb1c94154a | 28 | int org[7] = {0,0,0,0,0,0,0}; |
kit2 | 1:85eb1c94154a | 29 | int Nums[7] = {0,0,0,0,0,0,0}; |
kit2 | 1:85eb1c94154a | 30 | int counter = 0; |
kit2 | 1:85eb1c94154a | 31 | int count2 = 0; |
kit2 | 1:85eb1c94154a | 32 | |
kit2 | 1:85eb1c94154a | 33 | //------------------------------------------- Create the interrupt receiver object on pin 26 |
4180_1 | 0:e09703934ff4 | 34 | InterruptIn interrupt(p26); |
kit2 | 1:85eb1c94154a | 35 | |
4180_1 | 0:e09703934ff4 | 36 | |
kit2 | 1:85eb1c94154a | 37 | //-------------------------------------------------------- Setup the i2c bus on pins 28 and 27 |
kit2 | 1:85eb1c94154a | 38 | I2C i2c(p9, p10); |
kit2 | 1:85eb1c94154a | 39 | |
4180_1 | 0:e09703934ff4 | 40 | |
kit2 | 1:85eb1c94154a | 41 | //------------------------------------------ constructor(i2c object, i2c address of the mpr121) |
4180_1 | 0:e09703934ff4 | 42 | Mpr121 mpr121(&i2c, Mpr121::ADD_VSS); |
4180_1 | 0:e09703934ff4 | 43 | |
kit2 | 1:85eb1c94154a | 44 | //-------------------------------------------------------------------touch panel initialised |
kit2 | 1:85eb1c94154a | 45 | |
kit2 | 1:85eb1c94154a | 46 | |
kit2 | 1:85eb1c94154a | 47 | |
kit2 | 1:85eb1c94154a | 48 | //---------------------------------------------------------------------------------------------playing audio |
kit2 | 1:85eb1c94154a | 49 | AnalogOut DACout(p18); |
kit2 | 1:85eb1c94154a | 50 | DigitalOut digout(LED4); |
kit2 | 1:85eb1c94154a | 51 | Ticker tick; |
kit2 | 1:85eb1c94154a | 52 | SDFileSystem sd(p5, p6, p7, p8, "sd"); // NGX mbed base board |
kit2 | 1:85eb1c94154a | 53 | |
kit2 | 1:85eb1c94154a | 54 | #define SAMPLE_FREQ 40000 |
kit2 | 1:85eb1c94154a | 55 | #define BUF_SIZE (SAMPLE_FREQ/10) |
kit2 | 1:85eb1c94154a | 56 | #define SLICE_BUF_SIZE 1 |
kit2 | 1:85eb1c94154a | 57 | |
kit2 | 1:85eb1c94154a | 58 | void dac_out(void); |
kit2 | 1:85eb1c94154a | 59 | void play_wave(char *); |
kit2 | 1:85eb1c94154a | 60 | void cleanup(char *); |
kit2 | 1:85eb1c94154a | 61 | void fill_adc_buf(short *, unsigned); |
kit2 | 1:85eb1c94154a | 62 | void swapword(unsigned *); |
kit2 | 1:85eb1c94154a | 63 | |
kit2 | 1:85eb1c94154a | 64 | // a FIFO for the DAC |
kit2 | 1:85eb1c94154a | 65 | short DAC_fifo[256]; |
kit2 | 1:85eb1c94154a | 66 | short DAC_wptr; |
kit2 | 1:85eb1c94154a | 67 | short DAC_rptr; |
kit2 | 1:85eb1c94154a | 68 | short DAC_on; |
kit2 | 1:85eb1c94154a | 69 | |
kit2 | 1:85eb1c94154a | 70 | typedef struct uFMT_STRUCT { |
kit2 | 1:85eb1c94154a | 71 | short comp_code; |
kit2 | 1:85eb1c94154a | 72 | short num_channels; |
kit2 | 1:85eb1c94154a | 73 | unsigned sample_rate; |
kit2 | 1:85eb1c94154a | 74 | unsigned avg_Bps; |
kit2 | 1:85eb1c94154a | 75 | short block_align; |
kit2 | 1:85eb1c94154a | 76 | short sig_bps; |
kit2 | 1:85eb1c94154a | 77 | } FMT_STRUCT; |
kit2 | 1:85eb1c94154a | 78 | void play_wave(char *wavname) |
kit2 | 1:85eb1c94154a | 79 | { |
kit2 | 1:85eb1c94154a | 80 | unsigned chunk_id,chunk_size,channel; |
kit2 | 1:85eb1c94154a | 81 | // unsigned *data_wptr,data,samp_int,i; |
kit2 | 1:85eb1c94154a | 82 | unsigned data,samp_int,i; |
kit2 | 1:85eb1c94154a | 83 | short dac_data; |
kit2 | 1:85eb1c94154a | 84 | char *slice_buf; |
kit2 | 1:85eb1c94154a | 85 | short *data_sptr; |
kit2 | 1:85eb1c94154a | 86 | // char *data_bptr; |
kit2 | 1:85eb1c94154a | 87 | FMT_STRUCT wav_format; |
kit2 | 1:85eb1c94154a | 88 | FILE *wavfile; |
kit2 | 1:85eb1c94154a | 89 | long slice,num_slices; |
kit2 | 1:85eb1c94154a | 90 | DAC_wptr=0; |
kit2 | 1:85eb1c94154a | 91 | DAC_rptr=0; |
kit2 | 1:85eb1c94154a | 92 | for (i=0;i<256;i+=2) |
kit2 | 1:85eb1c94154a | 93 | { |
kit2 | 1:85eb1c94154a | 94 | DAC_fifo[i]=0; |
kit2 | 1:85eb1c94154a | 95 | DAC_fifo[i+1]=3000; |
kit2 | 1:85eb1c94154a | 96 | } |
kit2 | 1:85eb1c94154a | 97 | DAC_wptr=4; |
kit2 | 1:85eb1c94154a | 98 | DAC_on=0; |
kit2 | 1:85eb1c94154a | 99 | |
kit2 | 1:85eb1c94154a | 100 | led1=led2=led3=led4=0; |
kit2 | 1:85eb1c94154a | 101 | |
kit2 | 1:85eb1c94154a | 102 | wavfile=fopen(wavname,"rb"); |
kit2 | 1:85eb1c94154a | 103 | if (!wavfile) { |
kit2 | 1:85eb1c94154a | 104 | printf("Unable to open wav file '%s'\n",wavname); |
kit2 | 1:85eb1c94154a | 105 | exit(1); |
kit2 | 1:85eb1c94154a | 106 | } |
kit2 | 1:85eb1c94154a | 107 | |
kit2 | 1:85eb1c94154a | 108 | fread(&chunk_id,4,1,wavfile); |
kit2 | 1:85eb1c94154a | 109 | fread(&chunk_size,4,1,wavfile); |
kit2 | 1:85eb1c94154a | 110 | while (!feof(wavfile)) { |
kit2 | 1:85eb1c94154a | 111 | switch (chunk_id) { |
kit2 | 1:85eb1c94154a | 112 | case 0x46464952: |
kit2 | 1:85eb1c94154a | 113 | fread(&data,4,1,wavfile); |
kit2 | 1:85eb1c94154a | 114 | break; |
kit2 | 1:85eb1c94154a | 115 | case 0x20746d66: |
kit2 | 1:85eb1c94154a | 116 | fread(&wav_format,sizeof(wav_format),1,wavfile); |
kit2 | 1:85eb1c94154a | 117 | if (chunk_size > sizeof(wav_format)) |
kit2 | 1:85eb1c94154a | 118 | fseek(wavfile,chunk_size-sizeof(wav_format),SEEK_CUR); |
kit2 | 1:85eb1c94154a | 119 | // create a slice buffer large enough to hold multiple slices |
kit2 | 1:85eb1c94154a | 120 | slice_buf=(char *)malloc(wav_format.block_align*SLICE_BUF_SIZE); |
kit2 | 1:85eb1c94154a | 121 | if (!slice_buf) { |
kit2 | 1:85eb1c94154a | 122 | exit(1); |
kit2 | 1:85eb1c94154a | 123 | } |
kit2 | 1:85eb1c94154a | 124 | break; |
kit2 | 1:85eb1c94154a | 125 | case 0x61746164: |
kit2 | 1:85eb1c94154a | 126 | slice_buf=(char *)malloc(wav_format.block_align*SLICE_BUF_SIZE); |
kit2 | 1:85eb1c94154a | 127 | if (!slice_buf) { |
kit2 | 1:85eb1c94154a | 128 | exit(1); |
kit2 | 1:85eb1c94154a | 129 | } num_slices=chunk_size/wav_format.block_align; |
kit2 | 1:85eb1c94154a | 130 | samp_int=1000000/(wav_format.sample_rate); |
kit2 | 1:85eb1c94154a | 131 | |
kit2 | 1:85eb1c94154a | 132 | // starting up ticker to write samples out -- no printfs until tick.detach is called |
kit2 | 1:85eb1c94154a | 133 | tick.attach_us(&dac_out, samp_int); |
kit2 | 1:85eb1c94154a | 134 | DAC_on=1; |
kit2 | 1:85eb1c94154a | 135 | led2=1; |
kit2 | 1:85eb1c94154a | 136 | for (slice=0;slice<num_slices;slice+=SLICE_BUF_SIZE) { |
kit2 | 1:85eb1c94154a | 137 | fread(slice_buf,wav_format.block_align*SLICE_BUF_SIZE,1,wavfile); |
kit2 | 1:85eb1c94154a | 138 | if (feof(wavfile)) { |
kit2 | 1:85eb1c94154a | 139 | exit(1); |
kit2 | 1:85eb1c94154a | 140 | } |
kit2 | 1:85eb1c94154a | 141 | data_sptr=(short *)slice_buf; |
kit2 | 1:85eb1c94154a | 142 | for (i=0;i<SLICE_BUF_SIZE;i++) { |
kit2 | 1:85eb1c94154a | 143 | dac_data=0; |
kit2 | 1:85eb1c94154a | 144 | |
kit2 | 1:85eb1c94154a | 145 | // for a stereo wave file average the two channels. |
kit2 | 1:85eb1c94154a | 146 | for (channel=0;channel<wav_format.num_channels;channel++) { |
kit2 | 1:85eb1c94154a | 147 | switch (wav_format.sig_bps) { |
kit2 | 1:85eb1c94154a | 148 | case 16: |
kit2 | 1:85eb1c94154a | 149 | dac_data+=( ((int)(*data_sptr++)) +32768)>>5; |
kit2 | 1:85eb1c94154a | 150 | break; |
kit2 | 1:85eb1c94154a | 151 | } |
kit2 | 1:85eb1c94154a | 152 | } |
kit2 | 1:85eb1c94154a | 153 | dac_data>>=1; |
kit2 | 1:85eb1c94154a | 154 | DAC_fifo[DAC_wptr]=dac_data; |
kit2 | 1:85eb1c94154a | 155 | DAC_wptr=(DAC_wptr+1) & 0xff; |
kit2 | 1:85eb1c94154a | 156 | while (DAC_wptr==DAC_rptr) { |
kit2 | 1:85eb1c94154a | 157 | led1=1; |
kit2 | 1:85eb1c94154a | 158 | } |
kit2 | 1:85eb1c94154a | 159 | led1=0; |
kit2 | 1:85eb1c94154a | 160 | } |
kit2 | 1:85eb1c94154a | 161 | } |
kit2 | 1:85eb1c94154a | 162 | DAC_on=0; |
kit2 | 1:85eb1c94154a | 163 | led2=0; |
kit2 | 1:85eb1c94154a | 164 | tick.detach(); |
kit2 | 1:85eb1c94154a | 165 | led3=1; |
kit2 | 1:85eb1c94154a | 166 | free(slice_buf); |
kit2 | 1:85eb1c94154a | 167 | break; |
kit2 | 1:85eb1c94154a | 168 | case 0x5453494c: |
kit2 | 1:85eb1c94154a | 169 | fseek(wavfile,chunk_size,SEEK_CUR); |
kit2 | 1:85eb1c94154a | 170 | break; |
kit2 | 1:85eb1c94154a | 171 | default: |
kit2 | 1:85eb1c94154a | 172 | data=fseek(wavfile,chunk_size,SEEK_CUR); |
kit2 | 1:85eb1c94154a | 173 | break; |
kit2 | 1:85eb1c94154a | 174 | } |
kit2 | 1:85eb1c94154a | 175 | fread(&chunk_id,4,1,wavfile); |
kit2 | 1:85eb1c94154a | 176 | fread(&chunk_size,4,1,wavfile); |
kit2 | 1:85eb1c94154a | 177 | } |
kit2 | 1:85eb1c94154a | 178 | fclose(wavfile); |
kit2 | 1:85eb1c94154a | 179 | led1=0; |
kit2 | 1:85eb1c94154a | 180 | } |
kit2 | 1:85eb1c94154a | 181 | |
kit2 | 1:85eb1c94154a | 182 | |
kit2 | 1:85eb1c94154a | 183 | void dac_out() |
kit2 | 1:85eb1c94154a | 184 | { |
kit2 | 1:85eb1c94154a | 185 | if (DAC_on) { |
kit2 | 1:85eb1c94154a | 186 | digout=1; |
kit2 | 1:85eb1c94154a | 187 | DACout.write_u16(DAC_fifo[DAC_rptr]); |
kit2 | 1:85eb1c94154a | 188 | DAC_rptr=(DAC_rptr+1) & 0xff; |
kit2 | 1:85eb1c94154a | 189 | digout=0; |
kit2 | 1:85eb1c94154a | 190 | } |
kit2 | 1:85eb1c94154a | 191 | } |
kit2 | 1:85eb1c94154a | 192 | |
kit2 | 1:85eb1c94154a | 193 | |
kit2 | 1:85eb1c94154a | 194 | |
kit2 | 1:85eb1c94154a | 195 | |
kit2 | 1:85eb1c94154a | 196 | //--------------------------------------------------------------------------------------------- |
kit2 | 1:85eb1c94154a | 197 | |
kit2 | 1:85eb1c94154a | 198 | //-------------------------------------------------------------------------------obtaining input |
kit2 | 1:85eb1c94154a | 199 | |
4180_1 | 0:e09703934ff4 | 200 | void fallInterrupt() { |
kit2 | 1:85eb1c94154a | 201 | int key_code=0; |
4180_1 | 0:e09703934ff4 | 202 | int i=0; |
4180_1 | 0:e09703934ff4 | 203 | int value=mpr121.read(0x00); |
4180_1 | 0:e09703934ff4 | 204 | value +=mpr121.read(0x01)<<8; |
kit2 | 1:85eb1c94154a | 205 | |
4180_1 | 0:e09703934ff4 | 206 | i=0; |
4180_1 | 0:e09703934ff4 | 207 | // puts key number out to LEDs for demo |
kit2 | 1:85eb1c94154a | 208 | for (i=0; i<12; i++) |
kit2 | 1:85eb1c94154a | 209 | { |
kit2 | 1:85eb1c94154a | 210 | if (((value>>i)&0x01)==1) |
kit2 | 1:85eb1c94154a | 211 | { |
kit2 | 1:85eb1c94154a | 212 | key_code=i; |
kit2 | 1:85eb1c94154a | 213 | lcd.printf("%d", i); |
kit2 | 1:85eb1c94154a | 214 | if(counter < 7) |
kit2 | 1:85eb1c94154a | 215 | { |
kit2 | 1:85eb1c94154a | 216 | Nums[counter] = i; |
kit2 | 1:85eb1c94154a | 217 | counter++; |
kit2 | 1:85eb1c94154a | 218 | } |
4180_1 | 0:e09703934ff4 | 219 | } |
kit2 | 1:85eb1c94154a | 220 | } |
4180_1 | 0:e09703934ff4 | 221 | led4=key_code & 0x01; |
4180_1 | 0:e09703934ff4 | 222 | led3=(key_code>>1) & 0x01; |
4180_1 | 0:e09703934ff4 | 223 | led2=(key_code>>2) & 0x01; |
4180_1 | 0:e09703934ff4 | 224 | led1=(key_code>>3) & 0x01; |
4180_1 | 0:e09703934ff4 | 225 | } |
kit2 | 1:85eb1c94154a | 226 | |
4180_1 | 0:e09703934ff4 | 227 | |
kit2 | 1:85eb1c94154a | 228 | //------------------------------------------------------------------------------MAIN |
4180_1 | 0:e09703934ff4 | 229 | |
4180_1 | 0:e09703934ff4 | 230 | |
kit2 | 1:85eb1c94154a | 231 | int main() |
kit2 | 1:85eb1c94154a | 232 | { |
4180_1 | 0:e09703934ff4 | 233 | |
kit2 | 1:85eb1c94154a | 234 | //------------------------------------------------to start enter new password which user wants to set |
kit2 | 1:85eb1c94154a | 235 | lcd.cls(); |
kit2 | 1:85eb1c94154a | 236 | lcd.printf("enter your new password\n"); |
kit2 | 1:85eb1c94154a | 237 | play_wave("/sd/forest.wav"); |
kit2 | 1:85eb1c94154a | 238 | wait(0.5); |
4180_1 | 0:e09703934ff4 | 239 | |
kit2 | 1:85eb1c94154a | 240 | int k; |
kit2 | 1:85eb1c94154a | 241 | //----------------------------------------------enter password |
kit2 | 1:85eb1c94154a | 242 | while(1) |
kit2 | 1:85eb1c94154a | 243 | { |
kit2 | 1:85eb1c94154a | 244 | interrupt.fall(&fallInterrupt); |
kit2 | 1:85eb1c94154a | 245 | interrupt.mode(PullUp); |
kit2 | 1:85eb1c94154a | 246 | if(counter==7){ |
kit2 | 1:85eb1c94154a | 247 | break;} |
4180_1 | 0:e09703934ff4 | 248 | } |
kit2 | 1:85eb1c94154a | 249 | |
kit2 | 1:85eb1c94154a | 250 | |
kit2 | 1:85eb1c94154a | 251 | for (k=0; k<7; k++) |
kit2 | 1:85eb1c94154a | 252 | { |
kit2 | 1:85eb1c94154a | 253 | org[k]=Nums[k]; |
kit2 | 1:85eb1c94154a | 254 | } |
kit2 | 1:85eb1c94154a | 255 | |
kit2 | 1:85eb1c94154a | 256 | wait(1); |
kit2 | 1:85eb1c94154a | 257 | |
kit2 | 1:85eb1c94154a | 258 | AGAIN: |
kit2 | 1:85eb1c94154a | 259 | lcd.cls(); |
kit2 | 1:85eb1c94154a | 260 | lcd.printf("1-open door\n2-reset password"); |
kit2 | 1:85eb1c94154a | 261 | play_wave("/sd/forest.wav"); |
4180_1 | 0:e09703934ff4 | 262 | interrupt.fall(&fallInterrupt); |
4180_1 | 0:e09703934ff4 | 263 | interrupt.mode(PullUp); |
kit2 | 1:85eb1c94154a | 264 | |
kit2 | 1:85eb1c94154a | 265 | while (1) |
kit2 | 1:85eb1c94154a | 266 | { |
kit2 | 1:85eb1c94154a | 267 | counter=0; |
kit2 | 1:85eb1c94154a | 268 | if(Nums[0]==1) |
kit2 | 1:85eb1c94154a | 269 | { |
kit2 | 1:85eb1c94154a | 270 | lcd.cls(); |
kit2 | 1:85eb1c94154a | 271 | //---------------------------------------------------enter the password |
kit2 | 1:85eb1c94154a | 272 | lcd.printf("enter your password\n"); |
kit2 | 1:85eb1c94154a | 273 | play_wave("/sd/forest.wav"); |
kit2 | 1:85eb1c94154a | 274 | wait(1); |
kit2 | 1:85eb1c94154a | 275 | |
kit2 | 1:85eb1c94154a | 276 | while(1) |
kit2 | 1:85eb1c94154a | 277 | { |
kit2 | 1:85eb1c94154a | 278 | interrupt.fall(&fallInterrupt); |
kit2 | 1:85eb1c94154a | 279 | interrupt.mode(PullUp); |
kit2 | 1:85eb1c94154a | 280 | if(counter==7){break;} |
kit2 | 1:85eb1c94154a | 281 | } |
kit2 | 1:85eb1c94154a | 282 | if(counter == 7) |
kit2 | 1:85eb1c94154a | 283 | { |
kit2 | 1:85eb1c94154a | 284 | wait(1); |
kit2 | 1:85eb1c94154a | 285 | //lcd.printf("%d",Nums[4]); |
kit2 | 1:85eb1c94154a | 286 | for(k=0;k<7;k++) |
kit2 | 1:85eb1c94154a | 287 | { |
kit2 | 1:85eb1c94154a | 288 | lcd.printf("%d",Nums[k]); |
kit2 | 1:85eb1c94154a | 289 | wait(1); |
kit2 | 1:85eb1c94154a | 290 | } |
kit2 | 1:85eb1c94154a | 291 | 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 | 292 | { |
kit2 | 1:85eb1c94154a | 293 | lcd.cls(); |
kit2 | 1:85eb1c94154a | 294 | lcd.printf("password is correct, door open\n"); |
kit2 | 1:85eb1c94154a | 295 | servo=1; |
kit2 | 1:85eb1c94154a | 296 | wait(1); |
kit2 | 1:85eb1c94154a | 297 | lcd.cls(); |
kit2 | 1:85eb1c94154a | 298 | lcd.printf("opening door...\n"); |
kit2 | 1:85eb1c94154a | 299 | // play_wave("/sd/forest.wav"); |
kit2 | 1:85eb1c94154a | 300 | wait(10); |
kit2 | 1:85eb1c94154a | 301 | goto AGAIN; |
kit2 | 1:85eb1c94154a | 302 | } |
kit2 | 1:85eb1c94154a | 303 | else |
kit2 | 1:85eb1c94154a | 304 | { |
kit2 | 1:85eb1c94154a | 305 | lcd.cls(); |
kit2 | 1:85eb1c94154a | 306 | lcd.printf("password incorrect.retry\n"); |
kit2 | 1:85eb1c94154a | 307 | play_wave("/sd/forest.wav"); |
kit2 | 1:85eb1c94154a | 308 | goto AGAIN; |
kit2 | 1:85eb1c94154a | 309 | } |
kit2 | 1:85eb1c94154a | 310 | } |
kit2 | 1:85eb1c94154a | 311 | } |
kit2 | 1:85eb1c94154a | 312 | |
kit2 | 1:85eb1c94154a | 313 | |
kit2 | 1:85eb1c94154a | 314 | wait(1); |
kit2 | 1:85eb1c94154a | 315 | if(Nums[0]==2) |
kit2 | 1:85eb1c94154a | 316 | { |
kit2 | 1:85eb1c94154a | 317 | wait(1); |
kit2 | 1:85eb1c94154a | 318 | counter=0; |
kit2 | 1:85eb1c94154a | 319 | lcd.cls(); |
kit2 | 1:85eb1c94154a | 320 | lcd.printf("enter your old password\n"); |
kit2 | 1:85eb1c94154a | 321 | play_wave("/sd/forest.wav"); |
kit2 | 1:85eb1c94154a | 322 | while(1) |
kit2 | 1:85eb1c94154a | 323 | { |
kit2 | 1:85eb1c94154a | 324 | interrupt.fall(&fallInterrupt); |
kit2 | 1:85eb1c94154a | 325 | interrupt.mode(PullUp); |
kit2 | 1:85eb1c94154a | 326 | if(counter==7){break;} |
kit2 | 1:85eb1c94154a | 327 | } |
kit2 | 1:85eb1c94154a | 328 | |
kit2 | 1:85eb1c94154a | 329 | if(counter == 7) |
kit2 | 1:85eb1c94154a | 330 | { |
kit2 | 1:85eb1c94154a | 331 | |
kit2 | 1:85eb1c94154a | 332 | 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 | 333 | { |
kit2 | 1:85eb1c94154a | 334 | counter=0; |
kit2 | 1:85eb1c94154a | 335 | lcd.cls(); |
kit2 | 1:85eb1c94154a | 336 | lcd.printf("enter your new password"); |
kit2 | 1:85eb1c94154a | 337 | play_wave("/sd/forest.wav"); |
kit2 | 1:85eb1c94154a | 338 | while(1) |
kit2 | 1:85eb1c94154a | 339 | { |
kit2 | 1:85eb1c94154a | 340 | interrupt.fall(&fallInterrupt); |
kit2 | 1:85eb1c94154a | 341 | interrupt.mode(PullUp); |
kit2 | 1:85eb1c94154a | 342 | if(counter==7){break;} |
kit2 | 1:85eb1c94154a | 343 | } |
kit2 | 1:85eb1c94154a | 344 | |
kit2 | 1:85eb1c94154a | 345 | for (k=0; k<7; k++) |
kit2 | 1:85eb1c94154a | 346 | { |
kit2 | 1:85eb1c94154a | 347 | org[k]=Nums[k]; |
kit2 | 1:85eb1c94154a | 348 | } |
kit2 | 1:85eb1c94154a | 349 | |
kit2 | 1:85eb1c94154a | 350 | lcd.cls(); |
kit2 | 1:85eb1c94154a | 351 | lcd.printf("password changed"); |
kit2 | 1:85eb1c94154a | 352 | play_wave("/sd/forest.wav"); |
kit2 | 1:85eb1c94154a | 353 | goto AGAIN; |
kit2 | 1:85eb1c94154a | 354 | } |
kit2 | 1:85eb1c94154a | 355 | else |
kit2 | 1:85eb1c94154a | 356 | { |
kit2 | 1:85eb1c94154a | 357 | lcd.cls(); |
kit2 | 1:85eb1c94154a | 358 | lcd.printf("password incorrect.retry\n"); |
kit2 | 1:85eb1c94154a | 359 | play_wave("/sd/forest.wav"); |
kit2 | 1:85eb1c94154a | 360 | goto AGAIN; |
kit2 | 1:85eb1c94154a | 361 | } |
kit2 | 1:85eb1c94154a | 362 | } |
4180_1 | 0:e09703934ff4 | 363 | } |
kit2 | 1:85eb1c94154a | 364 | } |
kit2 | 1:85eb1c94154a | 365 | } |