3∏ Program Counter PROBLEM!

we have a program in which we like to count the number of turns made by our robot. For whatever reason, when our count increases to anything greater than 1 the 3∏ will not recognize it’s programming…
for example:
we program the robot to display the number of each turn after it makes a turn, but once the count > 1 it discontinues the display…

int main()
}
set_motors(-80,80);
delay_ms(200);
turn_val = 0;
if(turn_val == 0)
{
print(" turn 1 “);
delay_ms(200);
lcd_scroll(LCD_RIGHT, 3, 200);
clear();
lcd_goto_xy(3, 1);
turn_val++;
}
else if(turn_val == 1)
{
print(” turn 2 “);
delay_ms(200);
lcd_scroll(LCD_RIGHT, 3, 200);
clear();
lcd_goto_xy(3, 1);
turn_val++;
}
else if(turn_val == 2)
{
print(” turn 3 “);
delay_ms(200);
lcd_scroll(LCD_RIGHT, 3, 200);
clear();
lcd_goto_xy(3, 1);
turn_val++;
}
else if(turn_val == 3)
{
print(” turn 4 “);
delay_ms(200);
lcd_scroll(LCD_RIGHT, 3, 200);
clear();
lcd_goto_xy(3, 1);
turn_val++;
}
else if(turn_val == 4)
{
print(” turn 5 ");
delay_ms(200);
lcd_scroll(LCD_RIGHT, 3, 200);
clear();
lcd_goto_xy(3, 1);
turn_val++;
}
else
{
set_motors(0,0);
delay_ms(6000);
}
}


we also tried a for loop, and a switch statement. PLEASE HELP!!!

Hello.

Your program doesn’t have a main loop, so program execution just runs off the end of your program when it gets to the end of main(). Also, when you post code, please use the [ code ] [ /code ] tags to format it nicely.

- Ben

i apologize for the confusion, but that is the main loop, and I will b sure to put the proper quotations. I don’t think it would run if it were not in a main loop.

Your program has a main(), but I don’t see any loop in your code. Am I missing it somewhere? With no main loop, it will run through once, which seems to be exactly the behavior you’re seeing.

In C, program execution starts at the beginning of main() and runs until it reaches the end of main. It is up to you to write a main() that contains a loop so that program execution never reaches the end. It seems like you are confusing main() with the Arduino’s loop() function, but the two are not the same. The hidden main() used in the Arduino framework is written as:

int main()
{
  setup();
  while (1)
  {
    loop();
  }
}

- Ben

I did not include the main in my explanation, because I thought it would be understood that a main function is common to all C programming. I do have a main in my real program, but I did not type it in for this forum dialog.

Trying to help you is becoming increasingly frustrating. The program you posted above has a function called main(), and that main doesn’t contain a loop. How does the main you posted differ from your main in your “real program”?

In general, if you want help, please post your entire “real program”. How do you expect anyone to help you debug a loop problem without posting the part of your code that contains the loop???

- Ben

…ok…here’s an exact replica of the program sir…


I might be misreading your tone, but the sense I get from the multiple ellipses is that you think my request to see your entire program is overly demanding. Is this the case? What you did in this thread is like saying “my board doesn’t work” and posting a picture of your setup that shows you’re not applying power. Then, when someone points out that your power problem, you reply that you are powering your board in your “real setup”, thereby casting doubt on the validity of your entire initial “fake setup” photo. Asking someone to spend a lot of time thoroughly debugging an approximation of your program that clearly won’t work is quite lame.

At any rate, thank you for posting your full program. I don’t see anything off-hand that could explain your issues, but I think this could be a good learning experience for you on troubleshooting. The key is simplification. You have a lot of different things going on that should be completely independent of your problem, so you should start by stripping them out of your program, at which point one of two things will happen:

  1. Your program will start working and you will have found the source of your problem.
  2. You’ll have a program that doesn’t work but is only a few lines long. It will be much easier for others to help you figure out the problem when presented with such a short, simple program.

As a first step, I suggest you remove all of your set_motor() calls and take out the completely unnecessary lcd_scroll() calls. I’m envisioning something like:

while (1)
{
  if (turn_val < 1)
  {
    clear();
    print("turn 1");
    delay_ms(1000);
    turn_val++;
  }
  else if (turn_val < 2)
  {
    clear();
    print("turn 1");
    delay_ms(1000);
    turn_val++;
  }
  else ...

If it still doesn’t work, please post the simplified version of your program and I’ll take a look at it. Get to the point where you can have turn_val increment as you expect and then start adding back the extra stuff like motors and LCD scrolling.

- Ben

Wow, firstly I said sir because that is how I was taught to address a male. Secondly I have no problem with constructive criticism, but the tone in which you addressed me in this past message was not professional nor respectful at all. My choice in how I responded was out of frustration, because we were having a obvious lack of communication. For you to call someone lame for any reason, falsely or justly, is extremely unprofessional.

I didn’t call you lame, I said that your actions in this thread were lame and explained why. This is constructive criticism. That you still can’t see the lameness of it is very disappointing to me. You have lost a lot of my good will in this thread, and you continue to lose it by refusing to acknowledge or even address the validity of my complaints. Let me try another analogy, because I really want you to understand why what you did is so annoying:

Let’s say I ask you to help me figure out where I went wrong in solving a math homework problem, and you sit down and spend 30 minutes of your free time looking over my work in an attempt to help out. If when you point out where I went wrong I tell you, “oh, well I didn’t give you my actual homework solution, I just gave you a rough version of it; of course I did that part right in my real solution”, what do you think your reaction would be? Would that previous 30 minutes seem like a good use of your time?

Keep in mind that you are the one asking others to spend their time helping you. You should be doing everything in your power to make this as easy as possible for them, and you should expect people to get annoyed when you waste their time. And if you do waste their time, an acknowledgement coupled with an apology is way better than the response of “oh, you mind?”.

- Ben

Ok we’re obviously having a miscommunication issue, and continuing to attack each other is not going to solve this problem. I apologize for the inconvenience to you and your team members. After going through our threads I am noticing that the largest cause to our miscommunication is the choice of words. From now on I will ask exactly what I am looking for, before I reveal my problem.
My problem:
I can not correctly set up a counter via a for loop or switch statement. To trouble shoot this we have set a basic while loop to be run 4 times. It works for our baby-o, but is not working exactly how we would like it to for the 3π.

I appreciate the apology. The Baby Orangutan doesn’t have an LCD, so how do you know that it’s working on the Baby Orangutan? Can you post the code that works for you on the Baby O? Also, did you try my suggestions from this earlier post?

- Ben

the code was long so, I had to cut the print screen but it’s the entire program::




This was my test program on the baby-o, it flashes the red LED every time PC0 is active-high. The amount of flashes corresponds to the number of times an active-high is received; on the first active-high received it shines once, on the second time it shines twice, etc. This program works, and has been tested multiple times, but for some reason we’re having an issue with counting on the 3π.

What happens if you run this program on the 3pi with the PC1 test replaced by an equivalent PD0 test (or a user-button check)? Also, I don’t need actual screenshots of your program. It would probably be easier for you if you just copy the code and paste it into your post.

- Ben