View unanswered posts | View active topics It is currently Tue Jul 29, 2014 4:01 pm






Reply to topic  [ 2 posts ] 
Help with this code 
Author Message
Rookie

Joined: Fri Nov 22, 2013 10:15 am
Posts: 1
Post 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);
}
}
}
}
}


Fri Nov 22, 2013 10:20 am
Profile
Site Admin
Site Admin
User avatar

Joined: Tue Oct 09, 2012 10:34 am
Posts: 192
Post 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

_________________
Ryan Cahoon
CMU Robotics Academy
RVW Software Developer

Robot Potato Head; Virtual NXT


Wed Dec 11, 2013 4:19 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.