View unanswered posts | View active topics It is currently Sat Nov 01, 2014 7:18 am






Reply to topic  [ 2 posts ] 
bump switch 
Author Message
Rookie

Joined: Mon May 05, 2014 8:37 am
Posts: 1
Post bump switch
How do you program a bump switch to run repeatedly? I'd like to program a bump switch to run a command and repeat it every time I hit the switch. I am trying the following:

Code:

task main()
{
   while(SensorValue(touchSensor) == 0)      // Loop while robot's bumper/touch sensor isn't pressed in
   {
      // Do nothing
   }

   motor[rightMotor] = 63;                     // Motor on port2 is run at half (63) power forward
   motor[leftMotor]  = 63;                     // Motor on port3 is run at half (63) power forward
   wait1Msec(1500);                            // Robot runs previous code for 1500 milliseconds before moving on
}



It will only run once and will not restart each time I press the button. Please help! Thanks!


Mon May 05, 2014 8:48 am
Profile
Moderator
Moderator

Joined: Thu Jan 03, 2013 5:10 pm
Posts: 198
Location: The plateau north of the Ohio River Valley, also known as Cave Country.
Post Re: bump switch
Place the whole wait-then-act mechanism in a large loop, like this:

Code:

task main()
{
    while(you_do_not_want_to_move_on)  // This is the loop to add.
    {
       while(SensorValue(touchSensor) == 0)      // Loop while robot's bumper/touch sensor isn't pressed in
       {
          // Do nothing
       }

       motor[rightMotor] = 63;                     // Motor on port2 is run at half (63) power forward
       motor[leftMotor]  = 63;                     // Motor on port3 is run at half (63) power forward
       wait1Msec(1500);                            // Robot runs previous code for 1500 milliseconds before moving on

       [pseudo code] stopthemotors();  // otherwise your motors will not turn off in between button presses.
    }
}


_________________
I'm not a robot! I'm british! ~ quote from an asparagus
I am not a robot! I am a unicorn! ~ quote from a robot


Tue May 06, 2014 6:57 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:  



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