The code of above is what my team is using to drive the robot. Some problems we noticed would be that in a blank template the program runs fine. While in the competition program it glitches. When I mean by glitch it runs fine then a slight delay happens. This continues when we press either button. Why is this happening? How should we fix this problem, and how do you guys program to do the same task we are doing? Our task is that when 7u is pressed it goes clockwise. If we wanted to go counter clockwise then we would press 7D.
This code would also mean that if you happened to push both 7U and 7D at the same time, 7U would take precedence and it would spin clockwise. I would also probably have motor[port2] = 0; as well in the last set of brackets so that if you are not pushing either 7U or 7D, then the motor is not spinning.
No doubt someone else will ask for more information and then be able to give you a better answer, but that is as much as I can think of given the information provided. The main question I would ask is to describe this ‘delay’ in more detail - how long is it stopping for, does it then continue spinning afterwards, or is it stopping completely, etc.
I don’t understand the different ports 7 vs 2 either, but in the first sample of code the second if/else condition would set the port output to 0 after the first condition set it to 127. I’m not sure why these logic conditions seem to work sometimes and then give the results you are describing i.e. the difference between the standalone template and competition. I have set up code several times in the first method and found my error later.
The second snippit should give you control as you desire to control the motor with the caution as pointed out that one button takes priority if both are pressed.
Lol practically the same response from both of you. Anyway thanks, I LOVE elegant code. I practically made a whole library of functions so that my main program is nice and simple.
Interesting. I will probably use this from now on. I love elegant code. I pretty much have a dictionary of functions to keep my main tasks very simple. Also, I never new you could just say:
not really. I mean its just a bunch of functions for like drive train, lifts, and various other tasks i use. they’re quite simple really.
Edit If you want I can go back and annotate everything so it makes sense and then I can upload it to here if you want. Most of the functions are for programming autonomous modes.
Perl syntax can be nice too, since it lets you do post-conditionals.
x=5 if something;
I’ve not been able to get EasyC to do “short-circuit AND” correctly;
This would look something like this.
Btn7 AND (motor=127); // If Btn7 isn’t true, there is no point in doing the rest
Another method that does not use a change of flow if/then/else is this,
which only works if (true) = 1 and (false) = 0 and you can use them in math.
prev_value = motor = (prev_value) * !Btn7 + Btn7 * 127;
Please post if you have success with either of these methods.