#define buzzerPin 13 #define buzzerPin2 12 #define buzzerPin3 11 #define alarmTrigger 2 #define lockTrigger 8 #define lockTrigger2 9 #define lockTrigger3 10 #define lockArm 4 #define tamperPrevention 5 #define tamperPrevention2 6 #define tamperPrevention3 7 int lockArm_flag = 0; /*Keeps track of whether or not the lock alarm has been armed yet.*/ int loop_var; /*Used if the alarm is set to go off for a specified number of seconds. Uncomment to use.*/ int seconds=30; /*Used to specify how many seconds alarm will sound for if the option in alarmSound_ISR is chosen. Uncomment to use.*/ int alarm_Flag=0; void alarmSound(); /*Prototype for the function alarmSound_ISR.*/ void alarmISR(); void setup(){ /*BEGIN FUNCTION SETUP*/ pinMode(buzzerPin, OUTPUT); /*Sets the pin designated buzzerPin to output.*/ pinMode(buzzerPin2, OUTPUT); /*Sets the pin designated buzzerPin2 to output.*/ pinMode(buzzerPin3, OUTPUT); /*Sets the pin designated buzzerPin3 to output.*/ pinMode(alarmTrigger, INPUT); /*Sets the pin designated alarmTrigger to input.*/ pinMode(lockTrigger, INPUT); /*Sets the pin designated lockTrigger to input.*/ pinMode(lockTrigger2, INPUT); /*Sets the pin designated lockTrigger2 to input.*/ pinMode(lockTrigger3, INPUT); /*Sets the pin designated lockTrigger3 to input.*/ pinMode(lockArm, INPUT); /*Sets the pin designated lockArm to input.*/ pinMode(tamperPrevention, INPUT); /*Sets the pin designated tamperPrevention to input.*/ pinMode(tamperPrevention2, INPUT); /*Sets the pin designated tamperPrevention2 to input.*/ pinMode(tamperPrevention3, INPUT); /*Sets the pin designated tamperPrevention3 to input.*/ digitalWrite(alarmTrigger, HIGH); /*Turns on the pull-up resistor for the alarmTrigger pin.*/ digitalWrite(lockTrigger, HIGH); /*Turns on the pull-up resistor for the lockTrigger pin.*/ digitalWrite(lockTrigger2, HIGH); /*Turns on the pull-up resistor for the lockTrigger2 pin.*/ digitalWrite(lockTrigger3, HIGH); /*Turns on the pull-up resistor for the lockTrigger3 pin.*/ digitalWrite(lockArm, HIGH); /*Turns on the pull-up resistor for the lockArm pin.*/ digitalWrite(tamperPrevention, HIGH); /*Turns on the pull-up resistor for the tamperPrevention pin.*/ digitalWrite(tamperPrevention2, HIGH); /*Turns on the pull-up resistor for the tamperPrevention2 pin.*/ digitalWrite(tamperPrevention3, HIGH); /*Turns on the pull-up resistor for the tamperPrevention3 pin.*/ attachInterrupt(0,alarmISR,CHANGE); /*Sets the program to interrupt if the alarmTrigger pin changes.*/ digitalWrite(buzzerPin, HIGH); /*Turns on the buzzer to indicate the program is running.*/ digitalWrite(buzzerPin2, HIGH); /*Turns on the buzzer2 to indicate the program is running.*/ digitalWrite(buzzerPin3, HIGH); /*Turns on the buzzer3 to indicate the program is running.*/ delay(500); /*Delays 500 milliseconds.*/ digitalWrite(buzzerPin, LOW); /*Turns off the buzzer.*/ digitalWrite(buzzerPin2, LOW); /*Turns off the buzzer2.*/ digitalWrite(buzzerPin3, LOW); /*Turns off the buzzer3.*/ } /*END FUNCTION SETUP*/ void loop(){ /*BEGIN FUNCTION LOOP*/ if(digitalRead(lockArm)==LOW && lockArm_flag == 0){ /*Enters if the lockArm button is pressed and the lock alarm has not been armed yet.*/ delay(10); /*Delays 10 milliseconds to prevent bouncing.*/ lockArm_flag=1; /*Sets the flag saying the lock alarm is armed.*/ } delay(1000); /*Delays .1 second.*/ if(digitalRead(tamperPrevention)==HIGH || digitalRead(tamperPrevention2)==HIGH || digitalRead(tamperPrevention3)==HIGH){ /*Enters if the alarm has been tampered with (if the wire loop around the bicycle has been broken.*/ alarm_Flag=1; /*Calls the function alarmSound_ISR.*/ } if((digitalRead(lockTrigger)==HIGH || digitalRead(lockTrigger2)==HIGH || digitalRead(lockTrigger3)==HIGH) && lockArm_flag==1){ alarm_Flag=1; } if(alarm_Flag==1){ alarmSound(); } } /*END FUNCTION LOOP*/ /*To make the alarm so that the buzzers run for a preset number of seconds, leave the following *function the way it currently is. To make the alarm go off until a reset, comment out the for *loop below and uncomment the while loop. The number of seconds the alarm will sound for is set at the beginning of *the program by changing the value of the variable seconds. One reason to have the alarm turn off after a preset *number of seconds is to preserve battery life. */ /*In order to offer the user the most flexibility, there are three pins for each trigger and the buzzers. If you *do not wish to use any of the triggers, simply connect the pin to ground. Leaving the pin unconnected or *connected to +5V will set off the alarm. If you do not wish to use any of the buzzer pins, leave the pin unconnected. *Do not connect the pin to +5V or ground as this would cause a short with one depending on the state of the pin. */ void alarmISR(){ alarm_Flag=1; } void alarmSound(){ /*BEGIN FUNCTION alarmSound_ISR*/ // while(1){ /*Loops infinitely.*/ // digitalWrite(buzzerPin, HIGH); /*Turns the buzzer on.*/ // delay(5000); /*Delays for 5 seconds.*/ // digitalWrite(buzzerPin, LOW); /*Turns the buzzer off.*/ // delay(1000); /*Delays for 1 second.*/ // } for(loop_var=0; loop_var<(seconds/6); loop_var++){ /*Loops for seconds/6 times.*/ digitalWrite(buzzerPin, HIGH); /*Turns the buzzer on.*/ digitalWrite(buzzerPin2, HIGH); /*Turns the buzzer2 on.*/ digitalWrite(buzzerPin3, HIGH); /*Turns the buzzer3 on.*/ delay(5000); /*Delays for 5 seconds.*/ digitalWrite(buzzerPin, LOW); /*Turns the buzzer off.*/ digitalWrite(buzzerPin2, LOW); /*Turns the buzzer off.*/ digitalWrite(buzzerPin3, LOW); /*Turns the buzzer off.*/ delay(1000); /*Delays for 1 second.*/ } alarm_Flag=0; } /*END FUNCTION alarmSound_ISR*/