Help writing a program for basic stamp board
Sda7
Posts: 8
Hi all
Iam new to this forum and i dont have a good programming skills and i need a help in programming.
I need a program that when getting a signal from (IN3) = (logic 1) the servo turns to 90 degree and hold its position for 3sec then resetting back to 0 degree.
Board type 555-28188
Stamp BS2
PBASIC 2.5
Thats all
Thanks
Iam new to this forum and i dont have a good programming skills and i need a help in programming.
I need a program that when getting a signal from (IN3) = (logic 1) the servo turns to 90 degree and hold its position for 3sec then resetting back to 0 degree.
Board type 555-28188
Stamp BS2
PBASIC 2.5
Thats all
Thanks
Comments
I assume this a school assignment and that you have some other reference materials for your particular board as well. Is that true?
Doc
I know my program may be full of errors but this what i got so far
Duration VAR word
Duration = 0
PAUSE 10
DO
IF IN3 = 1 THEN
IF Duration < 1150 THEN
Duration = 350
ENDIF
ENDIF
PULSOUT 14, Duration
PAUSE 100
DEBUG HOME, DEC4 duration, " = duration" ( i dono what this line do)
LOOP
Parallax folks have spent a lot of time and energy making up tutorials like "What's a Microcontroller?" to help people get started with a Stamp. You'll learn more and better working your way through that and the "Basic Stamp Syntax and Reference Manual" than with folks here duplicating the effort.
Thats why i asked for help.
If i came empty handed and i said write me a program from scratch that would be lazy.
But i already have a code and i know how to get signal from (IN3) and move the servo to a certian location, but i dont know how make a timer to hold the positon of the servo then reset it back to its first position.
Writing the code for this Part of the program wont hurt anyone
The servo start the movement to the desired position when (IN4 = 1)
But it doesnt move back to the starting point when (IN4 = 0) or after the timer finish the 3 seconds.
Whats wrong with my code?
When IN4 is 1, your program will continually do the first action. When IN4 is 0, your program will continually do the second action. In either case, IN4 will be retested about every 2.6 seconds.
I suggest you throw out the IF statement for now and experiment with just
Try inserting DEBUG statements between the above statements and see what happens.
Actually, when working with any program it is a good practice to write the program in small steps. It can be tempting to write everything at once, especially when there is an example program provided. Do your best to avoid this temptation. If will actually save you hours of work over a one week period. For the StampWorks book that I am working through I often write two or three programs for each exercise in the book. I will often write little bits of the program and use DEBUG statements to pop up different values on the screen so I can immediately see what values are being used in the program.
A good trick to help you to figure out if the correct values are being calculated and used properly in your program is to insert PAUSE 500 or PAUSE some_number instructions that allow you to have a look at the values before the next values are calculated and displayed. Later you can remove the DEBUG and PAUSE statements to speed up your program. While I have not used this method, it is recommended to use it if you use a lot of DEBUG statements:
Conditional compilation statements is the method. An example appears on page 217 of the StampWorks PDF. It shows how to use an IF statement and a DEBUG statement as a block of code so that if you want the DEBUG's to disappear at run-time, you simply change one number in the program, in one place and they all disappear. If you have a lot of DEBUG's, it really speeds up the program.
Another good method used with DEBUG statements is to learn how to manipulate the cursor used to write values to the DEBUG terminal so that certain values will simply overwrite the old values. This provides the effect of a running clock or a running count depending on how you format the DEBUG's.
Good luck and have fun!
The StampWorks book is available for download on the Parallax website. Just search for the StampWorks kit and find the download link near the bottom on the page.