November 21, 2024, 08:36:48 PM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


How i make to different DATA Tables One for ON and One for OFF

Started by samsam, December 26, 2007, 08:50:03 AM

Previous topic - Next topic

samsam

Hi Every One

I have a question

I play with this for a day under stand how it works

What i do not understand how would setup another data table




' -----[ User Data ]-------------------------------------------------------

'                       +----------------------- hours   ($00 to $23)
'                       |    +------------------ minutes ($00 to $59)
'                       |    |    +------------- seconds ($00 to $59)
'                       |    |    |    +-------- event data
'                       |    |    |    |
Event1          DATA    $06, $00, $00, %00000001
Event2          DATA    $06, $00, $30, %00000010
Event3          DATA    $06, $01, $00, %00000100
Event4          DATA    $06, $15, $30, %00001000
Event5          DATA    $06, $30, $00, %00000000

EventsEnd       DATA    $99, $99, $99, %00000000
Sam

I Want  Thank You for All Of Your Time And Help

...............In Helping Getting Thing To Work........

samsam

JonnyMac

Thank You for helping me on the Parallax Fourm that help me understand how the data command
now i would like to understand how to set up another data table

Sun Hours =                       Out Side Light Hours =

10                                            7
11                                            6
12                                            5
13                                            4
14                                            3

This the kind of tables that i want to use for this Project

With one of the fader boards that i bought i am going to use this routine to control it
for the low voltage lighting that is in my yard

When i finsh this Project i will post it on the forum



Thank You For any help that you  give to understand how to set this up
Sam

I Want  Thank You for All Of Your Time And Help

...............In Helping Getting Thing To Work........

JonnyMac

Glad I could help with your other project.  Please describe your new project in detail, and let me figure out how best to solve it for you.  I'm confused by your partial description.
Jon McPhalen
EFX-TEK Hollywood Office

samsam

This what i want to is base on the amount of sun hour in a day
Then based on that i want to have that many hour that the Low Votage Lights run
 
I want to know what would be the best way to this and the only thing that i have come with is to use a lot of IF THEN Statements which i do not what to do

I want to  learn other way of writing code and beter way to write code

You can get this type of timer at Home Depo

The setup is as follow you can how many hours after sunset 2, 4, 6, 8  or Sun Set to sun rise or on all the time

Do not get wrong I like the idea but i want more in how you set it up this where i got the idea to make a timer that has a little more to it

It runs it self

But there two thing that i do not like with this type of timer one if  the power gose out then you have to reset it

To what setting that you other wise it stays OFF

The other thing that you have to adj the amount of hours when the season change and a  normanl timer that you set the time you adj for the same things and Day Light Saving Time and if the power gose out then you have to reset the time

What i want to do is have a routine that look at how many hours of sun light and base on that run the out side light for so many hour i have DS1302 working on a battery back and got it very well that took some doing

I want to have the same setup that i used for my pool pump timer where i wrote a routine that ON one hour OFF one hour

If the power gose off

No big deal it just starts the routine in this case i just want the routine to PICK UP where it was before the power when out

I am looking at pulg it in and it runs it self and no help from me or any one else

The routne below is the one that i use it taking an LED and using like an switch

If you need any more details Please let me know


IF Sun Hours =        THEN      DO this many HOURS    Out Side Light Hours =

Hrs of Sun =10                                       Hrs = 7 = ON  lights
Hrs of sun =11                                       Hrs = 6 = ON  lights
Hrs of sun =12                                       Hrs = 5 = ON  lights
Hrs of sun =13                                       Hrs = 4 = ON  lights
Hrs of sun =14                                      Hrs = 3 = ON  lights



Look:                '  File Name    Dual LED Switch
DO                   '  Author....   Sid Weaver
HIGH led             
LOW chg             
PAUSE dly1         
'charge             
LOW led              '  This is One LED Switch
HIGH chg
PAUSE dly1
'input
LOW led
INPUT chg
PAUSE dly2            'Changing This Value Will Change The Light Level Respone
DEBUG CR, DEC ? chg

IF chg = 0 THEN
GOTO Clock_Run
ENDIF

PAUSE dly3

LOOP
Sam

I Want  Thank You for All Of Your Time And Help

...............In Helping Getting Thing To Work........

samsam

JonnyMac

Thank You for your reply

One thing that want to add that onec i learn how to write a routine for this

I may want adj the time not for hour but in every 15 mins instead

But i will do this latter when I  understand how to write the basic part of the routine

Thank You For all of your help in the past
Sam

I Want  Thank You for All Of Your Time And Help

...............In Helping Getting Thing To Work........

JonnyMac

Sorry, Sam, I've never been accused of being the sharpest tool in the shed -- I still don't understand what you want your program to do.  I know it has something to do with the hours of sunlight in a day, but what?

Please help me and try again.  Don't worry about HOW to solve the problem, just define the problem; describe it as if it were a finished product that worked perfectly and you were teach me how to us it, not explaining the workings of the internals.
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

I can help you with one section:

QuoteIF Sun Hours =        THEN      DO this many HOURS    Out Side Light Hours =

Hrs of Sun =10                                       Hrs = 7 = ON  lights
Hrs of sun =11                                       Hrs = 6 = ON  lights
Hrs of sun =12                                       Hrs = 5 = ON  lights
Hrs of sun =13                                       Hrs = 4 = ON  lights
Hrs of sun =14                                      Hrs = 3 = ON  lights

In PBASIC, you have lots of choices -- with those values, it could be as simple as:

  hrs = 17 - sun

... or you could do this if you want the output timing to be variable:

  idx = sun - 10
  LOOKUP idx, [7, 6, 5, 4, 3], hrs


This works because the sunlight hours are contiguous values.  If they weren't, you could do this:

  LOOKDOWN sun, [10, 11, 12, 13, 14], idx
  LOOKUP   idx, [ 7,  6,  5,  4,  3], hrs


LOOKDOWN and LOOKUP use inline tables -- in this case they're a little easier to use than DATA tables.  Note that this code doesn't do any error trapping.  If you want to make the program bullet-proof, you might do something like this:

  idx = $FF
  LOOKDOWN sun, [10, 11, 12, 13, 14], idx
  IF (idx < 5) THEN
    LOOKUP idx, [ 7,  6,  5,  4,  3], hrs
  ELSE
    hrs = 5
  ENDIF


This will trap a bad value for "sun" and set "hrs" to the median output level.

Jon McPhalen
EFX-TEK Hollywood Office

samsam

JonnyMac

Thank You For your Reply

That is just what i Am LOOKING for I just did not know how to write it

Thank You For All Of Your Help In this Matter      :)
Sam

I Want  Thank You for All Of Your Time And Help

...............In Helping Getting Thing To Work........

samsam

JonnyMac

One question how do I write the ON OFF routine using what

I have only use the LookUp and Look Down commands once and that was in a Demo code
and i do real under stand how you use it and i have trouble sometimes understand what they have in Basic Stamp Help Examples

idx = $FF
  LOOKDOWN sun, [10, 11, 12, 13, 14], idx
  IF (idx < 5) THEN
    LOOKUP idx, [ 7,  6,  5,  4,  3], hrs
  ELSE
    hrs = 5
  ENDIF

Sam

I Want  Thank You for All Of Your Time And Help

...............In Helping Getting Thing To Work........

samsam

JonnyMac

( $FF )  Dose this mean hrs or something else

idx = $FF

Thank for all of your help
Sam

I Want  Thank You for All Of Your Time And Help

...............In Helping Getting Thing To Work........

JonnyMac

No, what I'm doing is pre-loading idx with $FF (255) so that if the LOOKDOWN fails (because the value for sun was not in the table) the program can see this.  If you read the help file for LOOKDOWN, you'll find that the output variable will not be changed if the target value is not in the table.  I suppose another way to do this if one only wanted to default to the median value is like this:

  idx = 2                                      ' default idx if error occurs
  LOOKDOWN sun, [10, 11, 12, 13, 14], idx
  LOOKUP   idx, [ 7,  6,  5,  4,  3], hrs


This will behave the same as before, but really doesn't let you do anything else on an error with the value of sun.

Jon McPhalen
EFX-TEK Hollywood Office

samsam

JonnyMac

Please help me and try again.
  Don't worry about HOW to solve the problem, just define the problem;

How  do i write the a routine that use the lookup and lookdown table to control a relay ON and OFF based on that

describe it as if it were a finished product that worked perfectly and you were teach me how to us it, not explaining the workings of the internals.

This how it will work when you frist power the Light Controler

(1) It looks to see if there day light

(2) If there is day light then count the amount of hours and based on that run the lights for that many hours

(3) This something that you brought up was
If there some thing wrong  let say that you power it up late in the day and it dose not match a  preset time that light would NOT be ON if this where the case
I do not think about that Thanks for point this out to me Pre set is four hours

(4) If you losted power that when the power came back on you have nothing to reset it pick where ever the routine was as if nothing happen it would just look to see if there is day light and just keep on going and if it is dark
Then which ever amount of hour of day light was logged then the lights would  be ON for that many hours

(5) You do not have to set a clock this done in the code routine

(6) You do not have change the time for day light saving time or for winter or summer

Please Let Me Know if you need me to explane any thing else

Thank You for explaning that to me in the other post
Thank You for all of your help
Sam

I Want  Thank You for All Of Your Time And Help

...............In Helping Getting Thing To Work........

JonnyMac

Okay, now I get it.

You'd need a "daylight detector" circuit.  With the Prop-2 you could use a CdS photocell and capacitor and read it with RCTIME.  What I would do is create a subroutine that  measures the light every minute and keeps track of daylight readings (you would have to determine light levels empirically).  If you measured N dark readings in a row you could assume it was dark and if dark, determine what to do with the daylight readings.  I would use 15 for N to start with so that you knew it was really dark, and not a cloud passing in front of the sun -- again, you'll have to experiment with the CdS circuit to determine what it reads in daylight versus when the sun has really gone down.  Also, I'd put the CdS in a ping pong ball to act as a difuser, kind of like the dome used on a photographer's light meter.

Here's a schematic for a light sensor circuit -- be sure to remove the ULN on the pin you use as this will interfere a bit with the circuit (Note: You don't need that 220-ohm resistor as it's built into the board).



Once you have your value, you can use LOOKDOWN and LOOKUP to deal with the readings.  LOOKDOWN in the BS2 is particularly powerful as it can be used with a comparison operator.  For example, you could do this:

  idx = 2
  LOOKDOWN dayMins, <=[600, 660, 720, 780, 840], idx
  LOOKUP   idx, [ 7,  6,  5,  4,  3], hrs


Notice how LOOKDOWN has <= in front of the table.  This will compare dayMins to the table entries and provide the index from the table of the first value that is less than or equal to a table entry.  Let's say you measure 740 minutes of daylight.  That LOOKDOWN would set idx to 3 because 720 is less than 780 and 780 is entry number three in the table.  That would cause the LOOKUP to set hrs to 4.

Jon McPhalen
EFX-TEK Hollywood Office

samsam

JonnyMac

Once you have your value, you can use LOOKDOWN and LOOKUP to deal with the readings.  LOOKDOWN in the BS2 is particularly powerful as it can be used with a comparison operator.  For example, you could do this:

  idx = 2
  LOOKDOWN dayMins, <=[600, 660, 720, 780, 840], idx
  LOOKUP   idx, [ 7,  6,  5,  4,  3], hrs

Notice how LOOKDOWN has <= in front of the table.  This will compare dayMins to the table entries and provide the index from the table of the first value that is less than or equal to a table entry.  Let's say you measure 740 minutes of daylight.  That LOOKDOWN would set idx to 3 because 720 is less than 780 and 780 is entry number three in the table.  That would cause the LOOKUP to set hrs to 4.

I like this even betters what you have here
I see what you are getting at
                                             Let's say you measure 740 minutes of daylight.  That LOOKDOWN would set idx to 3 because 720 is less than 780 and 780 is entry number three in the table.  That would cause the LOOKUP to set hrs to 4.

and that was something I had been thing about and not sure how deal with this item  unless
i do every thing in mins wwould this be better to do
Sam

I Want  Thank You for All Of Your Time And Help

...............In Helping Getting Thing To Work........

samsam

JonnyMac

How do I write the code to control a relay using the lookup and lookdown
table

idx = 2
  LOOKDOWN dayMins, <=[600, 660, 720, 780, 840], idx
  LOOKUP   idx, [ 7,  6,  5,  4,  3], hrs

Thank You for all of youhelp
Sam

I Want  Thank You for All Of Your Time And Help

...............In Helping Getting Thing To Work........