PDA

View Full Version : Need some help with some code



sam_sam_sam
08-15-2005, 12:10 AM
......HI .......
every one
...................

I would like THANK ANY ONE· that can help with·this· project

set var word
set1 var word
·
What i would like to know is if there i s a way to control the outputs with out using the PAUSE command
·This works but the ONE WITH OUT· SET1....
·I can only use·PAUSE 100... or·ANY HIGHER·the·LED BLINKS all the time
Now the one that use the SET1 work ok
I·want to do this control·OUTPUTS at diffrent COUNT POINTS let say at

..........10 count turn on one output for 1 sec· at..................
.......... 30 count turn on output two for 1 sec· at................
............3000 count turn on out put three for 1 sec...............
·when i have try to this it will STOP counting when it gets to the FRIST OUT PUT·
................note that i will be using RELAYS for LEDS....................
................note that....FOR set1=14 TO 14....... is to control more that ONE out put at the
same time i know this i was tring something......................
Can some one help with this project i would realy APRECIATE it

>>>>>>>>>>>>>>>>>>>>>>>>>>
......I had left this part out when i was coping and pasteing.........
also i will using a input· controling the out put

The input will be a VMD - 19 Video Motion Detector Module
I do have the data sheet for this module

main:
DO
I am sorry i had left this part out
·IF· set = 6000 THEN set = 0
·IF· set = 3000 THEN ledlight1
·IF rawdist < 1000 THEN set = set + 1
·IF· set >3 THEN set = set + 1
·IF· set = 5 THEN ledlight

LOOP

END
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
·-----[ Subroutines ]----
http://forums.parallax.com/images/smilies/idea.gif
···· ledlight:
····· FOR set1=14 TO 14·················· OR·················· ledlight:
·· HIGH set1·············································· ·················· HIGH 14
·· NEXT·············································· ···························· PAUSE 100···················
·· PAUSE 1000·············································· ················ LOW 14
····· FOR set1=14 TO 14·············································· GOTO main
·· LOW set1
·· NEXT
· GOTO main


·· ledlight1:········································ ········· OR·············· ledlight1:
····· FOR set1=15 TO 15················································ ··· HIGH 15
·· HIGH set1·············································· ························· PAUSE 100
·· NEXT·············································· ·································· LOW 15
·· PAUSE 1000·············································· ······················ set = 0
····· FOR set1=15 TO 15················································ ···· GOTO main
·· LOW set1
·· NEXT
·· set = 0
· GOTO main

THANK YOU FOR ANY HELP THAT YOU CAN GIVE ME· IN THIS MATTER

·samsam

........http://forums.parallax.com/images/smilies/jumpin.gif This GUY has gone MAD ..........





Post Edited (sam_sam_sam) : 8/14/2005 8:36:16 PM GMT

Chris Savage
08-15-2005, 02:40 AM
Sam,

·· Your code is wasting instructions, because the FOR...NEXT loops are only getting one pass.· Maybe it would be easier to explain what you're trying to do, and then get suggestions from there.· Please be clear.





▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)

sam_sam_sam
08-15-2005, 04:15 AM
Chris
When i was coping and pasteing i left out part of my code i am sorry about

I·want to do this controling THREE OUTPUTS at diffrent time·COUNT POINTS let say at

..........10 count turn on·ONE output for 1 sec· at..................
.......... 30 count turn on output·TWO for 1 sec· at................
............3000 count turn on out put·THREE for 1 sec...............



sam

Post Edited (sam_sam_sam) : 8/14/2005 8:37:36 PM GMT

Chris Savage
08-15-2005, 06:43 AM
Sam,

·· What are the counts?· Seconds?· Counts through a FOR...NEXT loop?· A running counter variable in a loop?· An external trigger?· High high does the count go before it rolls over?· This is all necessary to know how to proceed.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)

sam_sam_sam
08-15-2005, 08:17 AM
Chirs

I·know what i want·it to do and i think that
I·Do Not ask the right things please bear with me·it is
hard·for me to put in words
THANKs FOR YOUR HELP

What are the counts?

·The count is...... 10........ before
out put 1
come on

·ON··Seconds = ....1..... then OFF·... or longer maybe

the count is·....30... before
output 2
come on

ON··Seconds = ....1..... then OFF

the count is......·3000...... before
output 3

ON··Seconds = ....1..... then OFF

How HIGH·does the count go before it rolls over?
·3000 count...........reset to.......... "0"

Counts through a FOR...NEXT loop?

A running counter variable in a loop?

·Is this what you are talking about?

If·so is this the right way·to this?
If·I have miss the point of what you saying
show me some code·so·I can understand it.

This is what i· used when
I tried the pin sensor


·IF· set = 3000 THEN ledlight1
IF rawdist < 1000 THEN set = set + 1
·IF· set >3 THEN set = set + 1
·IF· set =·10 THEN ledlight


Some one in the forum said that i should use a
Video Motion Detector Module for what i want to do

An external trigger is ?
·Is the alarm output
IF·alarm output = high THEN set = set + 1
The input will be a VMD - 19
Video Motion Detector Module
I do have the data sheet for this module

PLEASE·LET KNOW NEED IF I NEEDTO CLEAR·UP ANY THING UP

THANKS FOR ALL OF YOUR HELP

sam

Post Edited (sam_sam_sam) : 8/15/2005 12:34:12 AM GMT

MacGeek117
08-15-2005, 08:34 AM
sam_sam_sam, please post your code in an attachment. That will make reading it alot easier.
bugg

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Boe-bot: $229


Toddler: $249

Learning Google is your friend: priceless

Chris Savage
08-15-2005, 12:29 PM
Sam,

·· What I was trying to determine was how long a count was.· It doesn't do much good to say count = count + one, and if count = 3000 then do something if there's no set time or event that corresponds to the count.· And again, what is incrementing the count variable?· Is there an external trigger?· If the program sitting in a loop just counting?· If so, how long does it take to count from the current value to the next.

·· I am just trying to help you here.· Many posts go unanswered because the original poster did not provide a clear picture of what they were trying to do.· I am clear on some points, but not on the overall picture.· I can write a program in about 45 seconds that will trigger the devices you mentioned at the intervals of count.· But I can also make that same program take anywhere from a fraction of a second to several hours to execute the different count values depending on how I increment the count variable.

·· One last factor to consider.· If you're having trouble programmatically controlling the output for one minute consider the 555 timer IC.· It can be set to trigger an output for one minute based on an output from the BASIC Stamp.· And the code would be simplified, if that would help you.



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)

Vern Graner
08-15-2005, 03:40 PM
sam_sam_sam said...
I would like THANK ANY ONE that can help with this project



As a quick suggestion, you might want to have a look at this thread as it contains a method to achieve what you described:

http://forums.parallax.com/showthread.php?p=538395 (http://forums.parallax.com/showthread.php?p=538395)

This thread describes "Sequencing" where you assign time lengths and states of outputs. Hope this helps http://forums.parallax.com/images/smilies/smile.gif

Vern

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔



Vern Graner CNE/CNA/SSE | "If the network is down, then you're
Senior Systems Engineer | obviously incompetent so why are we
Texas Information Services | paying you? Of course,if the network
http://www.txis.com | is up, then we obviously don't need
Austin Office 512 328-8947 | you, so why are we paying you?" ©VLG

sam_sam_sam
08-16-2005, 10:07 AM
Chris

What· I want to do is when the INPUT is·TRIGGERED·HIGH then turn
ON· OUTPUT 1 for 30 secound then OFF
wait for·60 secounds·then turn ON
OUTPUT2 for 2 secounds then OFF
wait ..2.. to ..5.. min then turn ON·...
OUTPUT 3 for 2 secounds then turn OFF
..This time i am sure how long it will be yet....
...ADD more TIME if TRIGGER.............
or END until the· NEXT TRIGGER

.....Is there a way to ADD more TIME if the INPUT is
TRIGGERED·WHILE·it is TIMING OUT··because i may
SHORTEN the TIME if this can be done

I would change it from 2 to 5 min· TO· 1 to 3 min or even
shorter


THANKS FOR YOUR HELP WITH THIS

sam

sam_sam_sam
08-16-2005, 10:22 AM
Vern

I looked at that post but i can under stand how write the code to vary the AMOUNT OF TIME for ONE OUTPUT at a time and for diffrent amount of TIME for EACH OUTPUT


THANK FOR THAT POST
I may want to use this in one of my up coming project but need to how do this
and THANKS FOR THE HELP

sam

Chris Savage
08-16-2005, 11:06 AM
Sam,

·· That last post painted me a very different picture of what you're trying to do.· At this point it looks like you'll be needing an RTC (Real-Time Clock) to keep track of time.· This no longer appears to be about events, but rather exact seconds now.· I would recommend reading the thread, "DS1302 Demo Code" in the projects forum.· The code there is designed to make it extremely easy to understand how to use the DS1302.

·· Now, if you need simpler (No dealing with 12/24 hour mode) or simply want to deal with the Raw Time (Seconds), then I would suggest downloading the StampWorks manual from our website.· In there is an example of using the DS1302 that focuses on one mode and also can track the time in seconds, which may help you in your situation.




▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)


Post Edited (Chris Savage (Parallax)) : 8/16/2005 2:31:35 PM GMT

sam_sam_sam
08-16-2005, 12:24 PM
Chris
·I have taken out of this what·I THINK· need
CODE wise "DS1302 Demo Code"
Please add ANY THING·else i need
THANKS FOR YOUR HELP

sam

Chris Savage
08-16-2005, 10:41 PM
Sam,

·· You removed all the subroutines.· There is no longer any code to deal with a DS1302 RTC.· As I am yet unaware of your programming skills, let me ask you, have you read through our "What's A Microcontroller?" text?· If not I would suggest downloading it from our website (It's a free downloading in PDF format).· It will help you familiarize yourself with many of the aspects of programming the BASIC Stamp.

·· The DS1302 code was recommended for using an external RTC.· If you don't have this chip, the code is useless.· Even then, you need the routines that communicate with the chip.· I have attached the DS1302 code for you.· It should be enough information to help you integrate a timer into your application.

·· We have a wealth of resources to make learning the BASIC Stamp pretty easy.· Let me know if you've read the above mentioned text, and I will try to come up with anything else that might help you.


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)


Post Edited (Chris Savage (Parallax)) : 8/16/2005 3:33:35 PM GMT

sam_sam_sam
01-22-2006, 07:21 AM
Chris or Anyone Else

I·can get the led to go on and off with the sechour
I can·read just seconds or seconds and minutes and hours

I want control 3·relays one at a time for so many seconds·each·( each one is a different amount of time )( Do Not Want To Use The Pause Command)

I would like to know how·to do is·reset sechour to read 00000 and start counting·over agian
Do i need to reset the sechour count·for each relay that·times out
Or can do one at a time·and then reset sechour on last··relay·that times out
I try a few thing but can not·get it to work

· THANKS FOR YOUR HELP That You Can Give In This Matter

Sam

Jon Williams
01-22-2006, 07:54 AM
This is one of the most confusing threads I've ever seen....

Okay, Sam, are you saying you want to turn on an LED when the clock time is exactly on the hour?· If yes, that's pretty easy: Just read the RTC and check the minutes and seconds for zero; when they're both zero you're dead on a new hour.

Main:
· GOSUB Read_RTC
· IF ((secs = 0) AND (mins = 0)) THEN·· ··· ' new hour?
··· Led = IsOn····························· ' yes, LED on
· ENDIF
· IF ((Led = IsOn) AND (secs = 15)) THEN··· ' has LED been on 15 seconds?
··· Led = IsOff·····························' yes, turn LED off
· ENDIF
· GOTO Main

This program will turn the LED on at the top of the hour (any hour) and turn it back off 15 seconds later.· You can change the turn-off point to anything you like.· Now... if you want to turn things on at a specific time (even minute) then I suggest you do something like this:

Main:
· GOSUB Read_RTC
· rawTime = hrs * 60 + mins················ ' convert time to minutes (0 - 1439)
· IF (rawTime = 390)·THEN·················· '·is it 6:30 AM? (6·x 60 + 30)
··· Led = IsOn····························· ' yes, LED on
· ENDIF
· IF (rawTime = 420) THEN·················· '·is it 7:00 AM?
··· Led = IsOff·····························' yes, turn LED off
· ENDIF
· GOTO Main

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax

sam_sam_sam
01-27-2006, 07:34 AM
HI JON and Everyone Else

I am sorry that (This is one of the most confusing threads I've ever seen....)
But from what you put in your post i did this
I learned ALOT and i want THANK Jon Williams ,Chris Savage and Tracy Allen
For all the time that you have taken to help me learn this




' -----[ Subroutines ]-----------------------------------------------------

Show_Time:
DEBUG HOME ' DEBUG Home Position

LOOKUP (day - 1), [Sun, Mon, Tue, Wed, Thu, Fri, Sat], work

DO
DEBUG " ", HEX2 month, "/", HEX2 date, "/", HEX2 year, " ", HEX2 hrs, ":", HEX2 mins, ":", HEX2 secs , CR
DEBUG "Hours In A Day... ", DEC2 hours, "...Minutes in an Hour...", DEC2 minutes, "....Second In AN minutes... ", DEC2 seconds, CR

'DEBUG DEC2 mins.NIB1, CR
' convert time to seconds (0 - 3259)

seconds = secs.NIB1 * 10 + secs.NIB0
minutes = mins.NIB1 * 10 + mins.NIB0
hours = hrs.NIB1 * 10 + hrs.NIB0


'Now this work But i what i want to know it is there an easyer was to this ?

'I have remove this line

'IF hours = 7 OR hours = 8 OR hours = 9 OR hours = 10 OR hours = 11 OR hours = 12 OR hours = 13 OR 'hours = 14 OR hours = 15 OR hours = 16 OR hours = 17 OR hours = 18 OR hours = 19 OR hours = 20 THEN
GOSUB VCR


·'I have change this line to read

If hours > 6 AND hours < 21 THEN GOSUB VCR



VCR:

'POWER CLEAR

IF ((minutes = 1) AND (seconds = 1)) THEN
HIGH 13
ENDIF
IF ((minutes = 1) AND( seconds = 30)) THEN
LOW 13
ENDIF


'VCR ON

IF ((minutes = 1) AND(seconds = 32)) THEN
HIGH 13
ENDIF
IF((minutes = 1) AND(seconds = 33)) THEN
LOW 13
ENDIF

'VCR OFF

IF ((minutes = 6) AND (seconds = 1)) THEN
HIGH 13
ENDIF
IF ((minutes = 6) AND (seconds = 2)) THEN
LOW 13
ENDIF


'POWER CLEAR

IF ((minutes = 15) AND (seconds = 1)) THEN
HIGH 13
ENDIF
IF ((minutes = 15) AND( seconds = 30)) THEN
LOW 13
ENDIF


'VCR ON

IF ((minutes = 15) AND(seconds = 32)) THEN
HIGH 13
ENDIF
IF((minutes = 15) AND(seconds = 33)) THEN
LOW 13
ENDIF


'VCR OFF

IF ((minutes = 20) AND (seconds = 1)) THEN
HIGH 13
ENDIF
IF ((minutes = 20) AND (seconds = 2)) THEN
LOW 13
ENDIF


'POWER CLEAR

IF ((minutes = 30) AND (seconds = 1)) THEN
HIGH 13
ENDIF
IF ((minutes = 30) AND( seconds = 30)) THEN
LOW 13
ENDIF


'VCR ON

IF ((minutes = 30) AND(seconds = 32)) THEN
HIGH 13
ENDIF
IF((minutes = 30) AND(seconds = 33)) THEN
LOW 13
ENDIF


'VCR OFF

IF ((minutes = 35) AND (seconds = 1)) THEN
HIGH 13
ENDIF
IF ((minutes = 35) AND (seconds = 2)) THEN
LOW 13
ENDIF


'POWER CLEAR

IF ((minutes = 45) AND (seconds = 1)) THEN
HIGH 13
ENDIF
IF ((minutes = 45) AND (seconds = 30)) THEN
LOW 13
ENDIF


'VCR ON

IF ((minutes = 45) AND(seconds = 32)) THEN
HIGH 13
ENDIF
IF ((minutes = 45) AND(seconds = 33)) THEN
LOW 13
ENDIF


'VCR OFF

IF ((minutes = 50) AND (seconds = 1)) THEN
HIGH 13
ENDIF
IF ((minutes = 50) AND (seconds = 2)) THEN
LOW 13
ENDIF

RETURN
ENDIF
RETURN
LOOP


THANKS FOR EVERYONES HELP

Sam

Post Edited (sam_sam_sam) : 1/28/2006 3:30:12 AM GMT

PJ Allen
01-27-2006, 08:41 AM
sam_sam_sam said...
But i what i want to know it is there an easyer was to this ?
IF hours = 7 OR hours = 8 OR hours = 9 OR hours = 10 OR hours = 11 OR hours = 12 OR hours = 13 OR hours = 14 OR hours = 15 OR hours = 16 OR hours = 17 OR hours = 18 OR hours = 19 OR hours = 20 THEN
GOSUB VCR
Yes --
If hours > 6 AND hours < 21 THEN GOSUB VCR

Is that all?

Post Edited (PJ Allen) : 1/27/2006 3:25:09 AM GMT

sam_sam_sam
01-28-2006, 02:08 AM
HI PJ Allen

THANKS FOR THE POST AND HELP
This works great THANKS

Sam

Post Edited (sam_sam_sam) : 1/28/2006 3:31:40 AM GMT

sam_sam_sam
01-28-2006, 11:58 AM
Hi Jon

I want to know what do you need in this GOSUB Read_RTC to make this work
Also· tried to use this and can not get this to work· Led = IsOn· and··Led = IsOff·

Led····· ·pin···· 13
ison···· ·con···· 1
isoff··· ·con···· 0·
rawtime·· var··· ·word

I think this right but i am not sure·············································· ·······

Main:
· GOSUB Read_RTC
· rawTime = hrs * 60 + mins················ ' convert time to minutes (0 - 1439)
· IF (rawTime = 390)·THEN·················· '·is it 6:30 AM? (6·x 60 + 30)
··· Led = IsOn····························· ' yes, LED on
· ENDIF
· IF (rawTime = 420) THEN·················· '·is it 7:00 AM?
··· Led = IsOff·····························' yes, turn LED off
· ENDIF
· GOTO Main

THANKS FOR ALL YOUR HELP

Sam

PJ Allen
01-28-2006, 09:47 PM
If all this "rawTime" etc. is the Read_RTC subroutine, then you need to make a slight change:


Read_RTC:
rawTime = hrs * 60 + mins
IF (rawTime = 390) THEN
Led = IsOn
ENDIF
IF (rawTime = 420) THEN
Led = IsOff
ENDIF
GOTO Main


You mentioned using a GOSUB to branch off to do Read_RTC, but you terminated the sub-routine with GOTO Main.· In that case, you should branch off with GOTO Read_RTC.· If want to terminate the sub-routine and go back to where you branched off from, then you should use GOSUB Read_RTC and replace GOTO Main with RETURN (assuming that you want to get out.)

sam_sam_sam
02-01-2006, 02:09 PM
Hi Jon or AnyOne Else

I want to know what do you need in this GOSUB Read_RTC to make this work

·File...... DS1302_Demo.bs2
'·· Purpose... Demonstrate The DS1302 Clock & RAM Functions
'·· Author.... Chris Savage -- Parallax, Inc.
'·· E-mail.... csavage@parallax.com (mailto:csavage@parallax.com)
'·· Started...
'·· Updated... 03-25-2005
·
'·· {$STAMP BS2}
'·· {$PBASIC 2.5}

Led····· ·pin···· 13
rawtime·· var··· ·word


debug·dec4 rawtime···or····debug·hex4 rawtime·
'Nothing·happen·to reading 0000···········································

Main:······································· 'I change the rawtime to = 2 minutes ahead of
· GOSUB Read_RTC···························· ' the Time
· rawTime = hrs * 60 + mins················ ' convert time to minutes (0 - 1439)
· IF (rawTime = 390)·THEN·················· '·is it 6:30 AM? (6·x 60 + 30)
··· Led = IsOn····························· ' yes, LED on
· ENDIF
· IF (rawTime = 420) THEN·················· '·is it 7:00 AM?
··· Led = IsOff·····························' yes, turn LED off
· ENDIF
· GOTO·Show_Time·
I also tried this and it did not work

Read_RTC:
··· rawTime = hrs * 60 + mins
··· IF (rawTime = 390)·THEN··················
····· Led = IsOn
··· ENDIF
··· IF (rawTime = 420) THEN······················
····· Led = IsOff
··· ENDIF
···GOTO·Show_Time··

Also· tried to use this and can not get this to work· Led = IsOn· and··Led = IsOff·
I think this right but i am not sure·
To turn led on and off but can not get this to work·

····················· 'I Also had·tried it·this way··
ison···· ·con···· 1·································· ison···· ·con···· 0
isoff··· ·con···· 0·································· isoff··· ·con·····1·

I could not get this to work the leds On and Off··············· http://forums.parallax.com/images/smilies/idea.gif

·· IF ((secs = 0) AND (mins = 0)) THEN·· ··· ' new hour?
··· Led = IsOn····························· ' yes, LED on
· ENDIF
· IF ((Led = IsOn) AND (secs = 15)) THEN··· ' has LED been on 15 seconds?
··· Led = IsOff·····························' yes, turn LED off·
· ENDIF

···· GOTO·Show_Time

This·works just fine··

IF ((secs = 0) AND (mins = 0)) THEN·· ··· ' new hour?
··· HIGH 13 OR HIGH led ' yes, LED on
· ENDIF
· IF ((mins = 0) AND (secs = 15)) THEN··· ' has LED been on 15 seconds?
··· Led = IsOff·····························' yes, turn LED off
· ENDIF

···· GOTO·Show_Time·······················

·····················

THANKS FOR ALL YOUR HELP················

···Sam

··Have They·Gone Mad· ..........http://forums.parallax.com/images/smilies/hop.gif·........http://forums.parallax.com/images/smilies/jumpin.gif .......Yes.............They Have .............

I might have to join them··................· http://forums.parallax.com/images/smilies/yeah.gif·................. Just Kidding...............http://forums.parallax.com/images/smilies/roll.gif·.......The END

Chris Savage
02-01-2006, 02:29 PM
sam,

·· Have you checked out the modifications made to the DS1302 Demo Code in the following thread?

http://forums.parallax.com/showthread.php?p=568430

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com (mailto:csavage@parallax.com)

sam_sam_sam
02-01-2006, 08:43 PM
·HI· Chris

That is just what i am looking for

THANK YOU FOR ALL OF YOUR HELP

Sam