ROBOTC.net forums
http://www.robotc.net/forums/

Help with this code
http://www.robotc.net/forums/viewtopic.php?f=11&t=7346
Page 1 of 1

Author:  swestendorf7 [ Fri Nov 22, 2013 10:20 am ]
Post subject:  Help with this code

I have labeled the lines of code in pseudocode to tell what each is doing. I want the program to turn the LEDOn if any of the three seatbelts are released. However, the untilRelease function only works with one sensor. Is it possible to make the untilRelease function cooperate with three different sensors?


task main()
{
while(1 == 1)//Program will loop continuously
{
turnLEDOff(Buzzer);//Turn the buzzer off right away
while(SensorValue(Force) == 1)//Program will loop while the child is in the seat
{
turnLEDOn(Buzzer);//Turn on the buzzer while the child is in the seat
if(SensorValue(Force) == 1)//If the child is in the seat
{
if(SensorValue(Seatbelt1) == 1)//If the first seatbelt is buckled
{
if(SensorValue(Seatbelt2) == 1)//If the second seatbelt is buckled
{
if(SensorValue(Seatbelt3) == 1)//If the third seatbelt is buckled
{
turnLEDOff(Buzzer);//If all three seatbelts are buckled and child is in seat, turn off buzzer
untilRelease(Seatbelt1);//Keep the buzzer off until seatbelt 1 is released
}
else//If the third seatbelt is unbuckled, turn the buzzer on
{
turnLEDOn(Buzzer);
}
}
else//If the second seatbelt is unbuckled, turn the buzzer on
{
turnLEDOn(Buzzer);
}
}
else//If the first seatbelt is unbuckled, turn the buzzer on
{
turnLEDOn(Buzzer);
}
}
}
}
}

Author:  rcahoon [ Wed Dec 11, 2013 4:19 pm ]
Post subject:  Re: Help with this code

Hi swestendorf,
Try removing this line
Code:
turnLEDOn(Buzzer);//Turn on the buzzer while the child is in the seat

and this line
Code:
untilRelease(Seatbelt1);//Keep the buzzer off until seatbelt 1 is released

and I think the program will do what you want.

To see why, try enabling View>>Preferences>>Highlight Program Execution, and run your program by clicking the Start button in the Program Debug after you compile and download, leaving your robot connected to the computer while the program is running. This will show you how your program is running and you can get a sense of which lines are executed when various combinations of your sensors are activated.

Cheers,
--Ryan

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/