Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unsigned int compArrays(void)
- {
- unsigned int correct=0; //number of matching knocks
- unsigned int secret; //programmed knock value
- unsigned int listen; //sensed knock value
- unsigned int error; //allowable percent error
- char k=0;
- secret=knock[PROGRAM][k];
- listen=knock[LISTEN][k];
- while((k<MAX_KNOCKS)&&(secret!=0)&&(listen!=0)) //check individual times and see if they're within 25% error
- {
- error=secret>>4;
- if((secret+error)>knock[LISTEN][k]>(secret-error)) //if within allowable error...
- {
- correct++; //increase number of correct knock times
- }
- k++;
- }
- if(correct==knockNumber) //if number of correct knocks match number of knocks...
- {
- char a;
- for(a=0; a<3; a++) //flash green LED a few times
- {
- GREEN_LED=1;
- Delay10KTCYx(3);
- GREEN_LED=0;
- Delay10KTCYx(5);
- }
- unlockDoor(); //proceed to unlock door
- }
- else //if incorrect...
- {
- char b;
- for(b=0; b<3; b++) //flash red LED a few times
- {
- RED_LED=1;
- Delay10KTCYx(3);
- RED_LED=0;
- Delay10KTCYx(5);
- }
- }
- }
Add Comment
Please, Sign In to add comment