Shop OBEX P1 Docs P2 Docs Learn Events
need info on for next code — Parallax Forums

need info on for next code

allieallie Posts: 107
edited 2011-06-05 14:22 in BASIC Stamp
I have relays hooked to the BS2 on pins p13 and p14. p13 and p14 hook to my control board, all works well.
I need help with the code.
I would like to know if this can be done and how?
I'll start.

For controller = 1 to 198

' Turn on relay 1 when numbers are odd
' Turn on relay 2 when numbers are even

Code here

next controller

allie

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-06-01 15:36
    First question is how you have things connected. How are the relays connected? What's the control board you mentioned.

    How about giving a try for the code. There are lots of ways to do what you want. How do you tell whether something is odd or even?
  • ercoerco Posts: 20,256
    edited 2011-06-01 15:42
    Hint: does x/2*2=x?
  • schillschill Posts: 741
    edited 2011-06-01 15:45
    I don't remember the exact syntax for the stamp, but if you check the lowest order bit of controller (bitwise and it with 1) you can tell whether it's odd or even.

    controller and 1 = 1 it's odd.
    controller and 1 = 0 it's even.

    Does the Stamp have a bitwise test function?
  • allieallie Posts: 107
    edited 2011-06-04 18:38
    Mike the relay board I mentioned, I made it myself and it works o.k. I used opto-couplers and uln's. I have no problem turning on the relays when I use the code High 13 and High 14 all works well.
    It's the code for the for next loop. I almost have it worked out and I'll let you know when I'm finished. I'll try to get a diagram with express sch tomorrow.
    Thanks for the other two replys. I was reading up on the math instructions from the BS2 online manual.

    allie
  • ercoerco Posts: 20,256
    edited 2011-06-05 14:22
    allie: try this and report back:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    controller VAR Byte
    FOR controller = 1 TO 198
    IF controller/2*2=controller THEN DEBUG DEC controller," even",CR
    IF controller/2*2<>controller THEN DEBUG DEC controller," odd",CR
    PAUSE 50
    NEXT
Sign In or Register to comment.