need help programming

Okay so I’m doing a project for my engineering class and I’m stuck on the programming because I wrote a code and I can’t finish it because everything I put after my loop doesn’t work. I don’t know what to do or if i m doing something wrong. I don’t know can you guys please help.

Right now my programming looks something like

Task
{
Turnflashlighton(port1);
Startmotor(port3,20);
While (1 == 1)
{
Startmotor (port2,20);
Wait(.3);
Stopmotor (port2);
Wait(.3);
}
Untilencodercounts (500, dgtl3);
Stopmotor(port3);
Wait(2);
Startmotor(port3);
And more things have to come after but I’m stuck after the loop because the encoder doesn’t stop after it reaches 500.

Okay so first, part
Turnflashlighton(port1);
It turns on my flashlight because I need a light for my light sensor because it will sort out a marble based off of how much light goes through.
Startmotor(port3,20);
This is running a belt, where my marble will fall onto the belt and move foward, so I need this to be running at all times unless I turn it off.
This is were it gets hard. My loop
While (1 == 1)
{
Startmotor (port2,20);
Wait(.3);
Stopmotor (port2);
Wait(.3);
}
Is what’s dispensing my marbles (15 marbles) onto the belt , so because I need It to let out one marble at time I have it running a loop that has some pauses in it.
Once it reaches the 500 on the belt, my encoder has to count the 500 and stop my belt(port3) because it will land in front of my light sensor with the flashlight pointing directly toward it. But my encoder isn’t counting, I think its because whatever comes after my loop, doesn’t want to read it. So I hope this makes it easier on you guys to help explain what I can do to make whatever comes after my loop work. Thanks :slight_smile: I’m using robotC and its in natural language

While (1 == 1)

This will loop for ever.

You have to put a condition in the while loop.

So it would be:

While(Untilencodercounts (500, dgtl3))
{
//body
}

I am guessing this is RobotC. Untilencodercounts (500, dgtl3) is a function you wrote or your teacher wrote for you to use, because this is not a standard function in RobotC. Next time let us know what language you are using and what micro controller you are using.

Well maybe you don’t even need the loop if Untilencodercounts (500, dgtl3) does not return until the encoders read 500. It is hard to tell because I am not sure what these functions do.

So you can try to do

Startmotor (port2,20);
Wait(.3);
Stopmotor (port2);
Wait(.3);

Untilencodercounts (500, dgtl3);

Stopmotor(port3);
Wait(2);
Startmotor(port3);