Shop OBEX P1 Docs P2 Docs Learn Events
BS1 Code Help — Parallax Forums

BS1 Code Help

Blackbird455Blackbird455 Posts: 124
edited 2007-09-02 17:53 in BASIC Stamp
OK, let me try this again,
·
·· I want to install a single button on a bs1 , that when pressed, will cause it to run a different set of instructions each time, say 4 different sets,

(FIRST SET)

SYMBOL reps = W1
SYMBOL i = W1··················· ' FOR...NEXT loop counter
Main:
FOR reps = 0 TO 65535 STEP 3000
FOR i = 1 TO 30
TOGGLE 2
PAUSE 18
NEXT
PAUSE 8
FOR i = 31 TO 60
TOGGLE 4
PAUSE 18
NEXT
PAUSE 8

NEXT

(SECOND SET)


FOR i = 1 TO 10
TOGGLE 2
PAUSE 40
NEXT
PAUSE 8
FOR i =·11 TO 20
TOGGLE 4
PAUSE 40
NEXT
PAUSE 8

NEXT

AND SO ON.....

How would I do this?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
ETERNAL NOOB, you could learn alot from a dummy

Comments

  • D FaustD Faust Posts: 608
    edited 2007-08-29 16:39
    If in0 = 1 then set1

    if in0 = 1 then set2

    if in0 = 1 then set3

    if in0 = 1 then set4

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    LOOKDOWN ThisThread, [noparse][[/noparse]Your_?, My_?, Cool_Thing], looknum
    LOOKUP looknum, [noparse][[/noparse]1, 2, 3], subnum
    ON subnum GOTO Hope_this_helps, Thanks!, WOW!!
    END 
    
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-08-29 17:16
    Blackbird -

    One thing is for certain. You shouldn't be assigning BOTH the variables reps and i to the same internal register (W1). One is going to clobber the other, and nothing will make sense.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Blackbird455Blackbird455 Posts: 124
    edited 2007-08-29 18:03
    ok bruce,

    Thats code that I took and modified.....I don't even know what that is !!!!!!!! lol what do you suggest?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ETERNAL NOOB, you could learn alot from a dummy
  • Blackbird455Blackbird455 Posts: 124
    edited 2007-08-29 18:29
    D Faust,

    I understand the IN0 lines, but take my code and show me where to put all that.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ETERNAL NOOB, you could learn alot from a dummy
  • D FaustD Faust Posts: 608
    edited 2007-08-29 18:42
    If in0 = 1 then
     gosub set1
    endif 
    if in0 = 1 then
     gosub set2
    endif 
    if in0 = 1 then 
     gosub set3 
    endif
    if in0 = 1 then 
     gosub set4
    endif
     
    set1:
     FOR reps = 0 TO 65535 STEP 3000
     FOR i = 1 TO 30
     TOGGLE 2
     PAUSE 18
     NEXT
     PAUSE 8
     FOR i = 31 TO 60
     TOGGLE 4
     PAUSE 18
     NEXT
     PAUSE 8
    

    does this help?· the sets are subroutines.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    LOOKDOWN ThisThread, [noparse][[/noparse]Your_?, My_?, Cool_Thing], looknum
    LOOKUP looknum, [noparse][[/noparse]1, 2, 3], subnum
    ON subnum GOTO Hope_this_helps, Thanks!, WOW!!
    END 
    
  • Blackbird455Blackbird455 Posts: 124
    edited 2007-08-29 18:53
    Not working, remember this is a bs1 "in0" must be pin0, and (If pin0 = 1 then..........."expected a variable") when I tokenized............. Did you actually enter this in the editor and try it , or you just dispensing untested information?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ETERNAL NOOB, you could learn alot from a dummy
  • D FaustD Faust Posts: 608
    edited 2007-08-29 19:03
    Sorry, I use BS2s.· I wanted to get the idea accross.· If you want something·done right you got to do it yourself.smilewinkgrin.gif··Did it work? (after you fixed it)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    LOOKDOWN ThisThread, [noparse][[/noparse]Your_?, My_?, Cool_Thing], looknum
    LOOKUP looknum, [noparse][[/noparse]1, 2, 3], subnum
    ON subnum GOTO Hope_this_helps, Thanks!, WOW!!
    END 
    
  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-29 19:04
    What D Faust provided uses a lot of features that are only available for the BS2, but the idea is correct. Here's the 4 button case.
    mainloop:
    if pin0 = 1 then set1 'wait for some button to be pressed
    if pin1 = 1 then set2
    if pin2 = 1 then set3
    if pin3 = 1 then set4
    goto mainloop
    set1:
    ' here you put what you want to do
    off1:
    if pin0 = 0 then mainloop 'wait for button to be released
    goto off1
    ' here you duplicate the same for the other sets
    
    
  • Blackbird455Blackbird455 Posts: 124
    edited 2007-08-29 19:07
    no it still does not work ,I know less bs1 than bs2's, I was not born with this information , so I am seeking the help of others, hey wait thats the way we learn things.........wow what a concept.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ETERNAL NOOB, you could learn alot from a dummy
  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-29 19:10
    For a single button that goes through 4 cases do:
    mainloop:
    if pin0 = 0 then mainloop ' wait for a push
    action = action + 1 ' increment the byte
    if action < 4 then doaction' check for wraparound
    action = 0 ' allowed values are 0,1,2,3
    doaction:
    if action = 0 then set1
    if action = 1 then set2
    if action = 2 then set3
    if action = 3 then set4
    waitoff:
    if pin0 = 0 then mainloop ' wait for release
    goto waitoff
    set1:
    ' do your stuff
    goto waitoff ' go wait for release and continue
    ' other stuff for sets 2,3,4
    
    

    There are more efficient ways to do this, but this is simple and, hopefully, clear.
    I have not tried this with the editor ... It may not be quite correct ... "Your mileage may vary".

    Post Edited (Mike Green) : 8/29/2007 7:15:06 PM GMT
  • Blackbird455Blackbird455 Posts: 124
    edited 2007-08-29 19:28
    Thanks again mike,

    Will try it when I get back

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ETERNAL NOOB, you could learn alot from a dummy
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-08-29 21:42
    Blackbird -

    I would replace the following WORD variable assignment:

    SYMBOL i = W1 ' FOR...NEXT loop counter

    with this BYTE variable assignment:

    SYMBOL i = B4 'FOR...NEXT loop counter - BYTE-sized (0-255)

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-29 22:46
    Did you change the SYMBOL definitions so that reps and i are now different variables?
  • Blackbird455Blackbird455 Posts: 124
    edited 2007-08-29 23:34
    Mike ,
    yes I did change SYMBOL definitions..........when I tokenize........."label is missing" between (action = action + 1)???? I have no idea.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ETERNAL NOOB, you could learn alot from a dummy
  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-30 01:03
    I didn't put in any SYMBOL definitions. I'm not trying to give you a complete, tested program. I'm trying to illustrate a technique. I assumed that you would look at what I wrote, try to understand it, then perhaps try to run it. If you tried to understand it, you would notice that "action" is not defined. Hopefully, you would understand PBasic well enough to know that all variables (other than those predefined in the manual like W0, etc.) have to be defined. By understanding the program, you would notice that it takes some pains to make sure that "action" only takes on values between 0 and 4 and that a byte would do (although a word would work). So, how would you fix the problem you've noticed?
  • Blackbird455Blackbird455 Posts: 124
    edited 2007-08-30 02:00
    yes I did notice that action is not defined.......................................but I do not know BS1 Pbasic syntax well enough to define it.............I figured it out, but do not know how to "define" it. All that I have learned in Pbasic is starting off with simple steps and putting them together. There is no school , there are no tests, for this, you just learn what you are taught, and NO , I have not been taught details like this, which is why I try to seek help on these forums. I ask specific questions , to get specific answers. Please tell me where all of you went to learn this , so that I can learn it too, and in about two years or so, I can finally press a button a few times to get a few different things to happen.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ETERNAL NOOB, you could learn alot from a dummy
  • FranklinFranklin Posts: 4,747
    edited 2007-08-30 02:16
    I recommend you start by reading this www.parallax.com/dl/docs/books/edu/wamv2_2.pdf

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Blackbird455Blackbird455 Posts: 124
    edited 2007-08-30 02:21
    Have the hard copy.............and the pdf

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ETERNAL NOOB, you could learn alot from a dummy
  • Blackbird455Blackbird455 Posts: 124
    edited 2007-08-30 02:24
    and its all about BS2 code and projects...................did every one of the projects, with sucess...............what I am looking for here is help with bs1 code, not bs2.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ETERNAL NOOB, you could learn alot from a dummy
  • RDL2004RDL2004 Posts: 2,554
    edited 2007-08-30 04:01
    You might try looking at the 1.9 version of the Basic Stamp manual, I found it a little easier for learning about the BS1. Its from before all the proliferation of different BS2 versions (when they started lumping all the commands together). In the 1.9 version the first half of the manual is nothing but BS1 - commands, code and examples. There are a few places where you can still download it. That's how I first got it, later I bought a used copy off eBay for about $5.

    Here is a link to one place you can get it:

    marwww.in2p3.fr/~levansuu/projets_es2i/Parallax/parallax%20website/stamps/stampdocs.htm

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Rick
  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-30 04:05
    The PBasic manual is pretty complete in its description of BS1 Basic. Pretty much everything I learned about it I got from the manual. It is interspersed with BS2 stuff, but the sections specific to the BS1 are very clearly marked. There are a few articles in the Nuts and Volts series of columns that are specific to the BS1, particularly about interpreting the DEBUG packets. I would suggest literally going through the manual in the introductory sections (Basic Stamp Architecture particularly) and marking the bits about the BS1. At the beginning of the Basic Stamp Command Reference, there's a categorical listing of commands where each command is marked as to the Stamp models it works with. Make a list of those that only exist on the BS1.

    You need to familiarize yourself with the processor and programming language you want to use. You might as well stop professing ignorance and get to work.
  • Blackbird455Blackbird455 Posts: 124
    edited 2007-08-31 20:17
    I believe that the title of this post is BS1 Code Help, Not HELP DAN MAKE BETTER DECISIONS .......I am not "professing ignorance" with my signature, it is merely a "disclaimer" , a warning, if you will, that I am not as experienced, or knowledgeable, as many people in these forums are. I ask questions to learn more about BS and SX code, and I learn a little here and there, and then put the pieces together, and accomplish what I am trying to do. I ask that if you do not know, or are just trying to get your "Total Posts" number higher, don't waste my time, and yours. If you do know , then please do not give me 90% of the answer , and toy with me for the other 10%, that makes me think that you do not know what you are talking about , or do not fully understand what you are dispensing. I have been working on Bell Model 206 helicopters for a long time, I know more about them than almost anyone I know. If someone wants to know something about them, I make every effort to clearly and thoroughly explain every detail , that I possibly can. I will never give someone 90% of the information when they ask, I will usually give 120%, covering all aspects, and from many angles. I guess it is my fault for setting my expectations so high.

    I guess, to sum it all up..............IF you want to help me, tell me exactly where I can find what I need, or just show me yourself........IF NOT........do not waste your time and my time and Parallax's server disc space.

    Thank you,
    Dan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ETERNAL NOOB, you could learn alot from a dummy
  • Mike GreenMike Green Posts: 23,101
    edited 2007-08-31 20:32
    I think you misunderstand the main purpose of this forum. It is precisely about sharing what individuals know which is likely not 100% of anything. There are very few people who frequent here who "toy" with other participants and they're pretty obvious. I don't think any of the regulars here care about "Total Posts". Unless someone has "Parallax" by their name, they're a volunteer who's trying to be helpful and the "Parallax" people have a day job beyond this forum. If you want someone else to hand you a 100% done, checked, verified piece of information, go search Parallax's tutorials and Nuts and Volts articles. There is a lot of information there, the examples are indeed tested and corrections are made (respecting the limited resources at hand).

    If you expect others to hand you complete information, you will occasionally find it here, but most of us don't have the time or interest to do that amount of work. Occasionally our interest is piqued by someone's description of a project and we'll put in a remarkable amount of effort to help out, but don't expect it.

    Post Edited (Mike Green) : 8/31/2007 8:37:23 PM GMT
  • Blackbird455Blackbird455 Posts: 124
    edited 2007-08-31 21:08
    "I didn't put in any SYMBOL definitions. I'm not trying to give you a complete, tested program. I'm trying to illustrate a technique."


    Thats the 90-10 that I am talking about..........I just wanted a basic example of code, that I could expand upon.........THIS is what I am talking about........Had you defined "action" I would have taken notice of it, and forever stored that little bit of information in the "knowledge gained" crevise of my brain.

    I have never done any exercises in SYMBOL definition, as my programs are generally not that complex........... now I know, since it has been brought to my attention, how to define symbols, because I followed the link that RLD2004 posted, that was very helpful.

    "If you expect others to hand you complete information, you will occasionally find it here, but most of us don't have the time or interest to do that amount of work."

    1. There has been more time and energy expended here on this topic than if someone had written the code from scratch, built a BS1 OEM, from scratch, plugged in the components, tested , and posted the results.

    2. Mike, I would appreciate it if you would stop assuming what I am thinking, and expecting...........Makes me think of what my latin teacher would always say about the word "assume"........... I do understand the purpose of this forum, and I don't expect others to go to work for me and hand me "complete" information. I regret that you interpret my intentions in this way.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ETERNAL NOOB, you could learn alot from a dummy
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2007-09-02 17:53
    This program works --·it waits for a·button push whereupon a fast flash routine executes;·then·it waits for a button push whereupon a slow flash routine executes; then it goes back to the top,·re-starting the process.

    ' {$STAMP BS1}
    ' {$PBASIC 1.0}
     
    DIRS = %00000001    ' Pin1 = 0 = input, Pin0 = 1 = output
    PINS = %00000000    ' preset -- input low, output low
     
    SYMBOL Times     = B0
    SYMBOL Fast_Rate = B1
    SYMBOL Slow_Rate = B2
     
    Fast_Rate = 100
    Slow_Rate = 400
    
    Faster:
      IF PIN1 = 0 THEN Faster    'wait for Pin1 = 1
      FOR Times = 0 TO 15
        PIN0 = 1
        PAUSE Fast_Rate
        PIN0 = 0
        PAUSE Fast_Rate
        NEXT
     
    Slower:
      IF PIN1 = 0 THEN Slower    'wait for Pin1 = 1
      FOR Times = 0 TO 7
        PIN0 = 1
        PAUSE Slow_Rate
        PIN0 = 0
        PAUSE Slow_Rate
        NEXT
     
      GOTO Faster
    
    263 x 262 - 6K
Sign In or Register to comment.