i am trying to create a program where the light sensor starts another program. however when i try to do this i keep on getting errors. this is what i have so far. just trying to move the motor.
#include <iostream> using namespace std; int main() { wait_for_light(0); if (analog10(0) >30); enable_motors(0,3); mtp(0,1000); mtp(3,1000); }
First if you have a #include with nothing after it the program shouldnt be able to compile
and if you just want to wait for the light you can remove the if(analog10(0) > 30); as how you wrote it it wont do anything and wait_for_light will already wait for the light to be turned on after calibration is complete. I may be wrong but I do not believe that you have to do enable_motors. Also at the end you need to sleep to allow the motors to finish moving you do this with bmd(motor). The final thing though is more of a personal choice and that is to use mrp instead of mtp. Here is the code I would use instead:
//define the light sensor so its a little more readable
#define LIGHT 0
using namespace std;
int main()
{
wait_for_light(LIGHT);
mrp(0,500, 1000);
mrp(3,500, 1000);
bmd(0);
bmd(3);
}
This will wait for the light then move forward 1000 ticks at 500 ticks a second(unless i got the last two arguments backwards)
The reason the include wasn't showing up was because of html weirdness. I went ahead and encapsulated your code in <c> blocks to prevent that from happening.
I think the error is caused by the lack of definition of the
enable_motors(0, 3);
function.ruler501 is correct about the if not functioning as expected. Remember that an if is executed only once. It does not wait for a condition to be true to continue.
I would recommend using a while loop to wait for a condition to be true. You can find examples in KISS's built in documentation.
Or, if this is a competition robot, it is strongly recommended you use the wait_for_light(int port); function. This allows you to calibrate your robot for the possibly stronger or weaker lighting at the tournament.
Good Luck!
Braden McDorman
Developer of the KIPR Link, KISS IDE, KIPR's 2D Simulator, and CBCJVM.
Reach me at bmcdorman(cat)kipr(dog)org where (cat)=@ and (dog)=. if you need assistance of any kind.
thanks every thing now works great.