Responding to "wierdoreedyboy" on Thread " Limit Switch Programming Problems"

For Starters, your comments say that:
“int Limit1; //Limit switch plugged into port 5”

but when you read the Limit Switch, you have:
“Limit1 = GetDigitalInput ( 4 ) ;”

I would guess that when your Sonar value changes, it causes the Limit1 value to go from a ‘1’ to a ‘0’, thus exiting your “while ( Limit1 == 1 )” loop.

Second, (not currently needed for your program, but…) don’t forget to place an “endless loop” around all the code you want to execute over and over again. e.g. “while(1)”

Looks like a good start…

One way to keep all of these straight is with #DEFINE’s (Global variables). Say
#DEFINE Limit_1 4; //Not exact sytax, use EasyC to get it correct
Then say “Limit1 = GetDigitalInput ( Limit_1 ) ;” and use the variable Limit_1 any time referencing the specific PWM port of for (or whatever it is defined as)

I think that MarkO nailed it.

The StartUltra and GetUltra, and GetDigital function calls are all looking at input port 4. That ain’t right.

Additionally, Sofa gives good advice, and I want to add to it. If you are going to #DEFINE an input port, then have the concept of input port embedded in the name you use. I recommend a name like “DIG_IN_PORT_LIMIT_1”. The longer name will help you avoid confusing the definition with the values you might read from the port and simply store in a variable called “Limit_1”.

Another hint is making the text of every printf unique. Instead of printing out “Limit1 = __” in four spots (can lead to confusion), print out “Limit_1 = ___ at A”, “Limit_1 = ___ at B”, “Limit_1 = ___ at C”, etc.

Blake

Thank you so much! I took your advice and it works just the way I want it to. I guess sometimes you need someone else to look at it to see what you did wrong. By the way, do you have any other suggestions about how my code is written? If you don’t that’s okay because you already told me how to fix my problem.

Thanks again,
Reed