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

Please help with bumpswitch!
http://www.robotc.net/forums/viewtopic.php?f=11&t=5899
Page 1 of 1

Author:  aero13 [ Wed May 29, 2013 7:32 pm ]
Post subject:  Please help with bumpswitch!

This is What I have
Code:
 #pragma config(Sensor, in3,    pot,            sensorPotentiometer)
#pragma config(Sensor, dgtl4,  bumpSwitch,     sensorTouch)
#pragma config(Sensor, dgtl6,  bump2,          sensorTouch)
#pragma config(Motor,  port2,           theMotor,      tmotorVex393, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//
task main()
{
 while(true){
 
 
untilBump(dgtl4);
{
 if(SensorValue(pot) < 50)
 {
 motor[theMotor]=30;
 }
 if(SensorValue[pot] > 3000)
 {motor[theMotor]=-30;}
}
untilBump(dgtl6);
{
 motor[theMotor] = 0;}
}
}

I want the program to turn on if and only if "bumpSwitch" has been pressed and released not simply pressed and held, and turn of when "bump2" is pressed and released. This program only works when I hold down bumpSwitch and continue to hold it. Other wise the motor just runs continuously and I don't have enough experience to figure out what the problem is. Please help

Author:  mightor [ Thu May 30, 2013 5:59 am ]
Post subject:  Re: Please help with bumpswitch!

Please do not send PMs to ask for help. If I send it to you via PM, then nobody else will benefit from it later. When you post a question, allow 24 hours for people to respond. Just keep that in mind for next time.

Anyway, I played around a bit with your program and this is what I came up with. It doesn't do the bumped thing for the second switch because that would make your program quite a bit more complicated but it simply waits for you to press that button and will continue to run the program while you keep your fingers away from it.

Code:
#pragma config(Sensor, in3,    pot,            sensorPotentiometer)
#pragma config(Sensor, dgtl4,  bumpSwitch1,    sensorTouch)
#pragma config(Sensor, dgtl6,  bumpSwitch2,    sensorTouch)
#pragma config(Motor,  port2,           theMotor,      tmotorVex393, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
  // Wait for the bumpSwitch to be bumped
  untilBump(bumpSwitch1);
 
  // This runs until the bumpSwitch2 switch changes to true
  // That only happens when it is pressed.
  while (SensorBoolean[bumpSwitch2] == false)
  {
     if(SensorValue(pot) < 50)
     {
       motor[theMotor]=30;
     }
    
     if(SensorValue[pot] > 3000)
     {
       motor[theMotor]=-30;
     }
   }
  motor[theMotor] = 0;
}


Regards,
Xander

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