Go Down

Topic: Help with some programming!! (Read 2 times) previous topic - next topic

kurtselva

Quote
Complete
code
is
essential.

Describing
what
the
code
actually
does
is,
too.


Look at my first 3 posts

PaulS

Code: [Select]
       if (setCounter == 1)                                        // if set counter is 1
     else if (setCounter == 2) 
else if (setCounter == 3)                                          // if set counter is 3
    else if (setCounter == 4)                                         // if set counter is 4
     else if (setCounter == 5)                                           // if set counter is 5
     else if (setCounter == 6)                                           // if set counter is 6
     else if (setCounter == 7)

Wouldn't a switch statement make more sense? Wouldn't some functions help?

Why can't you use Tools + Auto Format to indent the code properly? Why didn't you attach the code instead of spreading t across multiple posts?

What exactly IS the code doing? How does that differ from what you want?

UKHeliBob

As Paul asked, you need to tell us what is not working.

The servo() function appears to be called once for each day that feeding is needed (numberofdays) and is called twice each day, but only if setCounter is 7
Code: [Select]
    else if (setCounter == 7)
    {
      if (feedinterval == 2)
      {
        for (int j = 0; j <= numberofdays; j++)
        {
          servo();
          delay (12000);
        }
      }
    }

This is in the loop() function so, if nothing happens to stop it the next time through loop() it will happen all over again.  This is the reason that I suggested you keep a count of how many times the servo had moved and stop it happening once the required number of moves has taken place.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

PaulS

Quote
This is the reason that I suggested you keep a count of how many times the servo had moved and stop it happening once the required number of moves has taken place.

Alternatively, set setCounter back to 0 once the servo movement is done.

kurtselva

Ok let me explain the code better:

user enters the following information using pushbuttons into a LCD display:
1) Feedinterval; this sets the interval between each feed and ranges from 2 -4. So if 2 is entered, then feed interval will be 12 hrly, 3 - 8hrly and 4 - 6 hrly
2) number of days for the feeding to continue. ranges from 1 to 10. SO if 2 is entered, then feeding will go one for 2 days etc
3) timefor first feed (this part will only come into play after I have worked on the existing problem)

So lets have a scenario: user inputs feedinterval= 2 and numberofdays = 2:
The servo will rotate a total of 2 times per day; so 4 times for 2 days..

For testing purpose, I cant wait for 12 hr interval. So I am testing with 12 sec interval instead.

SO the problem is I am not able to stop the servo from rotating even after the condition stated in the for loop has been satisfied..


Go Up