I am trying to program a PIR motion sensor that will sense motion and turn on a piezo buzzer and LED light that are all connected on a Parallax Propeller. The code is written in C and used on Simple IDE. The code works to where the motion is sensed and turns on the buzzer and LED but I can't turn it off unless I unplug the circuit. I was thinking of adding a push button that will turn it off and reset it to the previous state. Any advice?
Code:
/* SERIAL_TERMINAL USED */
// ------ Libraries and Definitions ------
#include "simpletools.h"
// ------ Global Variables and Objects ------
int pir;
// ------ Function Declarations ------
void led2();
// ------ Main Program ------
int main() {
// Wait 20 to 30 seconds for PIR to calibrate or"warm up"
print("Wait about 20 seconds for PIR to calibrate...........");
print("\r");
pause(20000);
term_cmd(CLS);
// Once the PIR detects movement, it will send a HIGH or a value of 1 out from its OUTPUT pin
while (1) {
pir = input(5);
if (pir == 1) {
cog_run(led2, 128);
while (1) {
print("Intruder Alert!");
print("\r");
freqout(4, 500, 1000);
term_cmd(CLS);
pause(1000);
}
}
}
}
// ------ Functions ------
void led2() {
while (1) {
high(2);
pause(500);
low(2);
pause(500);
}
return 0;
}
//