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

Touch Sensor - Bump Count
http://robotc.net/forums/viewtopic.php?f=1&t=10257
Page 1 of 1

Author:  Hobbes [ Wed Jan 14, 2015 12:14 am ]
Post subject:  Touch Sensor - Bump Count

Hi,

I am new to RobotC and am working on learning some of the different features. My brick is an EV3 and I have RobotC 4.27.

So, I am trying to write a background task which stops the program when the touch sensor has been bumped 3 times. I thought it would be simple enough to use the getBumpedValue() function in a while loop. It seems that the getBumpedValue() function doesn't always reset as I would expect. Then the second time I run the program, the while loop gets skipped (touch sensor never presses) and the program instantly ends.

So, Any idea why the following 4 examples work or don't work?

1) This only works once. The second time the program is run, the while loop is skipped over:

resetBumpedValue(Touch);
while(getBumpedValue(Touch) < 3)
{
}

stopAllTasks();

2) This works perfectly. I can run the program multiple times.

while(getBumpedValue(Touch) < 3)
{
}
resetBumpedValue(Touch);
stopAllTasks();


3) This works perfectly. I can run the program multiple times.

string sValue;

sValue = getBumpedValue(Touch);
displayBigTextLine(1, sValue);
sleep(1000);

resetBumpedValue(Touch);

sValue = getBumpedValue(Touch);
displayBigTextLine(1, sValue);
sleep(1000);

while(getBumpedValue(Touch) < 3)
{
}
stopAllTasks();

4) This only works once. The second time the program is run, the while loop is skipped over(this is the same as #3 except no time delays):

string sValue;

sValue = getBumpedValue(Touch);
displayBigTextLine(1, sValue);

resetBumpedValue(Touch);

sValue = getBumpedValue(Touch);
displayBigTextLine(1, sValue);

while(getBumpedValue(Touch) < 3)
{
}
stopAllTasks();

Author:  mightor [ Wed Jan 14, 2015 3:05 am ]
Post subject:  Re: Touch Sensor - Bump Count

The bump count reset issue was fixed in the latest version of ROBOTC: http://www.robotc.net/blog/2014/12/23/r ... 4-28-beta/

= Xander

Author:  Hobbes [ Wed Jan 14, 2015 2:46 pm ]
Post subject:  Re: Touch Sensor - Bump Count

Thanks. I will download the 4.28 beta this evening.

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