East Anglia (UK)
Offline
Edison Member
Karma: 49
Posts: 1432
May all of your blinks be without delay
|
 |
« Reply #30 on: February 11, 2013, 02:28:35 pm » |
That first Serial.println() statement is crap.
What's wrong with it ?
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 316
Posts: 35552
Seattle, WA USA
|
 |
« Reply #31 on: February 11, 2013, 02:29:32 pm » |
What's wrong with it ? It's not in loop. It should be saying that it is.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 98
|
 |
« Reply #32 on: February 11, 2013, 02:32:53 pm » |
What meaning has setCounter == 5 got in your program ?
You are calling the servo() function from 8 places in your code. That can't be right, can it ? You only need to call it when the clock time equals the requested feed time.
I have just realised something. You don't seem to have any form of clock in your program to compare the feeding times with, or have I missed something fundamental ?
setCursor basically switches my programme to "run" mode.. From what I have tested so far, the programme seems to be working as how I wanted it to.. And you are right, I decided to do away a clock. Instead, I am using the delay() function as a clock. In the program, the delay (2000) increases the current hour by 1 in every 2sec. This is because it is more feasible to test it this way as I do not have to wait for minutes or hours to see if the code works. But in actual programme, I will change the (2000) to (3600000) which is 1hr. So the currenthour should increase by 1 every 1 hr, and when it reaches 24, it resets to 0 (therefore acting as a 24 hr clock). I hope it works...
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 98
|
 |
« Reply #33 on: February 11, 2013, 02:35:40 pm » |
My earlier post brings me back to this qn: Is there a limit to the delay () function? As in the max milis value it can take?
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 316
Posts: 35552
Seattle, WA USA
|
 |
« Reply #34 on: February 11, 2013, 02:40:59 pm » |
Is there a limit to the delay () function? As in the max milis value it can take? Yes, there is. Parameters ms: the number of milliseconds to pause (unsigned long) Any value that fits in an unsigned long is valid, though not necessarily reasonable, input.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 98
|
 |
« Reply #35 on: February 11, 2013, 02:49:31 pm » |
I have just realised something. You don't seem to have any form of clock in your program to compare the feeding times with, or have I missed something fundamental ?
Guess it is hard to see when the servo actually rotates from my code cos I did not include comments in the code. So basically, totalfeedforfeedinterval calculates the total feeds needed according to the user input: eg if user input feedinterval = 2 and numberofdays = 2, then totalfeedforfeedinterval is 2 x 2 =4 Also, the user the set the 1st feed hour and the current hour. So, when the program is in run mode, i.e setCursor = 5, the currenthour will increment according to the delay () in the code. When the currenthour = 1stfeedhour, the servo will rotate once. And according to the programme chosen, the servo will then rotate at the specified intervals (if you see the codes you should understand this). And there is this int feeddone which increments whenever the servo rotates. So, when the feeddone = totalfeedforfeedinterval, the programme exits run mode, i.e setCursor = 0
|
|
|
|
« Last Edit: February 11, 2013, 02:51:41 pm by kurtselva »
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 98
|
 |
« Reply #36 on: February 11, 2013, 02:54:18 pm » |
Parameters ms: the number of milliseconds to pause (unsigned long) Any value that fits in an unsigned long is valid, though not necessarily reasonable, input. [/quote] ermm..I am new to programming language (that is why my programme only consists of the basic if/else and for statements  )... So what is meant by unsigned long? And is 3600000 fits in an unsigned long?
|
|
|
|
|
Logged
|
|
|
|
|
East Anglia (UK)
Offline
Edison Member
Karma: 49
Posts: 1432
May all of your blinks be without delay
|
 |
« Reply #37 on: February 11, 2013, 02:56:10 pm » |
Sorry, I had forgotten that you were using delay() to do the timing. I is not very accurate but for your application that will probably not matter. There are other ways of creating a delay that do not use delay() and they don't suffer from the number of milliseconds ever being too big and also allow the system to do other things while the wait goes on but I suggest that you get the basics working first, which you seem to be close to doing.
By the way, I still don't understand the many calls to servo(). It seems unnecesary somehow.
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 316
Posts: 35552
Seattle, WA USA
|
 |
« Reply #38 on: February 11, 2013, 02:59:16 pm » |
So what is meant by unsigned long? And is 3600000 fits in an unsigned long? It's time you became acquainted with the reference page.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 98
|
 |
« Reply #39 on: February 11, 2013, 03:09:19 pm » |
So what is meant by unsigned long? And is 3600000 fits in an unsigned long? It's time you became acquainted with the reference page. Unsigned long variables are extended size variables for number storage, and store 32 bits (4 bytes). Unlike standard longs unsigned longs won't store negative numbers, making their range from 0 to 4,294,967,295 (2^32 - 1). Thanks for referring me to the reference page..haha So my delay (3600000) should work!! 
|
|
|
|
« Last Edit: February 11, 2013, 03:13:37 pm by kurtselva »
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 98
|
 |
« Reply #40 on: February 11, 2013, 03:24:52 pm » |
By the way, I still don't understand the many calls to servo(). It seems unnecesary somehow.
Hmm well, for different feeding interval, the timing for the servo to rotate differs: for interval 2, it rotates at firstfeedhour and at m = firstfeedhour +12 hr..so I called 2 servo () after each condition is true for interval 3, it rotates at firstfeedhour, at m = firstfeedhour +8 and at n = m +8.. so I called 3 servo () after each condition is true and similar for interval 4 The good thing is that the programme is working..but I do not know if it could be done simpler..
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 98
|
 |
« Reply #41 on: February 11, 2013, 03:28:16 pm » |
There are other ways of creating a delay that do not use delay() and they don't suffer from the number of milliseconds ever being too big and also allow the system to do other things while the wait goes on but I suggest that you get the basics working first, which you seem to be close to doing.
I guess it is time to try other ways of creating a delay  Any suggestions?
|
|
|
|
|
Logged
|
|
|
|
|
East Anglia (UK)
Offline
Edison Member
Karma: 49
Posts: 1432
May all of your blinks be without delay
|
 |
« Reply #42 on: February 11, 2013, 04:24:27 pm » |
Look at the BlinkWithoutDelay example sketch. As to your current program calling servo() many times, I would do it like this calculate numberOfTimesToFeed from information entered by the user put the delays between feeds in an array waitingTimes[] set feedcounter =0
while feedcounter less than numberOfTimesToFeed set wait time to waitingTimes[feedcounter] wait move servo increment feedcounter exit while if feedcounter equals numberOfTimesToFeed else go back and do it again
|
|
|
|
|
Logged
|
|
|
|
|
|