I am newer to Robot C. I am teaching the PLtW: POE course. We have a Machine Control Project and the students have decided to try and create a security system.
Goals: Use a bump to arm the alarm, wait 10 s for person to leave, notice an intruder, after 3 seconds sound the alarm unless the button is pressed.
Here is what I have programmed to try and make it work, but I am running into issues:
task main()
{
bool enter = false; //enter = intruder
untilBump(dgtl1); //arm the system
wait(10);
while(enter==false)
{
if(SensorValue[dgtl10]>20) //no intruder detected using ultrasonic
{
enter = false; //no intruder detected
}
else //intruder detected
{
clearTimer(T1);
while(time1[T1]<=3001)
{
if(SensorValue[dgtl1]==0 && time1[T1]>3000) //button not pressed within 3 s
{
enter = true; //intruder detected
}
else //button is pressed or more than 3 seconds have passed
{
enter = false; /*no intruder detected, I want this line of code to kick back out to the initial while statement to continue looking for intruders*/
}
}
}
while(enter) //while an intruder is detected
{
while(1==1) //continuously run this code
{
turnFlashlightOn(port1, 127); //flash lights as alarm
wait(0.5);
turnFlashlightOff(port1);
wait(0.5);
}
}
}
Help! Any and all advice is welcome. Thanks!