A member on my local forum posted a write up on how he used the same controller to control his aquarium light. I liked the idea and made a light similar to his original design. He posted his script as well which I adapted and modified it to suit my application. I understand what the script does and how it flows, but to get it to do exactly what i have imagine is what I'm having a little problem with. Here is the script.
- CODE: SELECT ALL EXPAND
begin
closeAllCh
ON_Royal_Blue
on_blue
on_white
6 delay_hours
OFF_white
off_blue
off_royal_blue
10 delay_minutes
repeat
############
sub ON_Royal_Blue
############
0
begin
dup 10816 less_than while
1 plus
180 delay
dup 2 servo
dup 3 servo
repeat
drop
return
############
sub ON_Blue
############
0
begin
dup 9500 less_than while
1 plus
180 delay
dup 4 servo
dup 5 servo
repeat
drop
return
############
sub ON_White
############
0
begin
dup 7552 less_than while
1 plus
360 delay
dup 0 servo
dup 1 servo
repeat
drop
return
############
sub OFF_white
############
7552
begin
dup -1 greater_than while
dup 0 servo
dup 1 servo
1 minus
360 delay
repeat
0 0 servo
0 1 servo
drop return
############
sub OFF_Blue
############
9500
begin
dup -1 greater_than while
dup 4 servo
dup 5 servo
1 minus
180 delay
repeat
0 4 servo
0 5 servo
drop return
############
sub OFF_Royal_Blue
############
10816
begin
dup -1 greater_than while
dup 2 servo
dup 3 servo
1 minus
180 delay
repeat
0 2 servo
0 3 servo
drop return
####################
####################
sub closeAllCh
######################
0 0 0 0
0 0 0 0
7 servo 6 servo 5 servo 4 servo
3 servo 2 servo 1 servo 0 servo
1000 delay
return
#####################
sub delay_seconds
#####################
begin
dup while
1 minus 1000 delay
repeat
drop return
#######################
sub delay_minutes
#####################
begin
dup while
1 minus 60 delay_seconds
repeat
drop return
#####################
sub delay_hours
#####################
begin
dup while
1 minus 60 delay_minutes
repeat
drop return
####################
return
What I have is an LED light with 6 channels. 2 white (servo 0 and 1), 2 royal blue (servo 2 and 3) and 2 blue (servo 4 and 5) channels. I have a timer that turns on the whole system at a certain time and the controller will control when and which led to turn on or off. here is my thought process:
-Once the system is turned off, I want all channels to be off
-The royal blue LED will turn on first, starting off at its minimum value and slowly ramping up to its maximum value in 30 mins
-The blue LED will turn on after the royal blue is at maximum power, slowly ramping up from its minimum value to a certain point (~85% of maximum) in 30 mins.
-The white LED will turn on after the blue LED is finish, slowly ramping from its minimum value to a certain point (~70% of maximum) in 1 hour.
-All LEDs will stay at their current position for 6 hours
-The White LED will slowly dim from its current value to minimum and turn off in 1 hour
-The blue LED will slowly dim from its current value to minimum and turn off in 30 mins
-The royal blue LED will slowly dim from its maximum value to minimum and off in 30 mins.
-The controller will not move for another 10 mins, just incase the timer doesnt match up completely with the controller and stays on when the script is finished.
I have ran the script for 2 days now and so far I noticed the time commands I have set in the program doesnt match up with what I had in mind. The first day it was an hour off so I messed with the script (just trial and error) the second day it was 15 mins off. Which im beginning to wonder if there are something wrong with my script. So my question is, are my time commands inline to what i want to do? how do i fix this?
------------------------------------------------
Re: Help with programming Pololu Maestro 12
by DavidEGrayson
Hello.
I don't see anything wrong with your script, but please keep in mind that the Maestro's internal clock is not as accurate as a watch. The crystal itself has a 0.1% tolerance, so it could lose or gain as much as 86 seconds every day. Also, the Maestro has many tasks to take care of concurrently, so the execution of time of the script can sometimes be hard to predict.
I see you have a lot of arbitrary numbers in your code that affect how long it will take. Have you calculated how long each part of the code should take and made sure that it adds up to 24 hours?
In order to prevent noticeable drift over the months, I would power the Maestro from a wall power adapter that is in turn powered by some sort of standard AC outlet timer. I would expect these timers to be much more accurate than the Maestro. The timer should turn the Maestro off for some time every night in order to reset the Maestro's clock and the state of your script. Then you don't actually have to worry about doing the calculations to make sure that your loop takes exactly 24 hours to execute.
--David
没有评论:
发表评论