While I was coding the V5 distance sensor, I wasn’t able to figure out what commands I should be using to code it. We use the V5 pro coding studio. Should I start with, if(Distance.objectDistance(inches)? How do I determine how far we can be from an object. If possible, please provide an example. Need help!
Distance.objectDistance(inches)
returns the number of inches you are from an object. How you use that value is really up to you. You could, for example, decide that you were only interested in objects closer than 12 inches, then you would have code something like this.
while(1) {
if( Distance.objectDistance(inches) < 12 ) {
// object is closer than 12 inches, do something clever
}
this_thread::sleep_for(10);
}
VEXcode V5 Pro does have one example program, perhaps try that first and modify as necessary.
3 Likes
Should be:
while(1) {
if( Distance.objectDistance(inches) < 12 ) {
// object is closer than 12 inches, do something clever
}
this_thread::sleep_for(10);
}
*Missing an open parenthesis before the “1” in the while loop. Small error but in-case someone inexperienced decides to copy-paste in the future, I thought I’d make the correction.
2 Likes
Yes, the perils of typing code on an iPad.
Pride made me fix it
5 Likes
thanks for the help, we really appreciate it
1 Like