Shop OBEX P1 Docs P2 Docs Learn Events
Changing a variable with a pulse. — Parallax Forums

Changing a variable with a pulse.

IroneIrone Posts: 116
edited 2012-10-01 21:20 in BASIC Stamp
Hello,

I need to know how to change a variable, I will call clock, by increasing the number with a positive pulse and decreasing it with a negative pulse. The variable will be a nib and I need to change it between 0 and 9. Thanks for any help.

Comments

  • ercoerco Posts: 20,256
    edited 2012-09-29 19:28
    What's a negative pulse?
  • IroneIrone Posts: 116
    edited 2012-09-29 19:52
    Hello,

    I read in the help file on pulsout that if the pin is negative, it reads positive for the specified time and then goes back to negative. Also if the pin reads positive, it reads negative for the specified time and then goes back to positive. I am using toggle to change my variable. I may be wrong thinking that a change in the plus or minus could change the value of my variable but I am new to BC2 and old in age. If this is not possible I will change my program to a 1 or a 0 and figure out a way to do it differently.
  • IroneIrone Posts: 116
    edited 2012-09-29 22:45
    Hello.

    I am a certain believer of call and effect, If you checked my previous post a signal of plus or minus should have been made to my variable, Why would they make a function that sends a plus or minus pulse if it would not affect any other function? I am very new to BS2 but am confused,
  • V-manV-man Posts: 10
    edited 2012-09-30 00:49
    Irone,

    The negative and positive terminology being used in the PULSOUT description refers to the direction of the change in signal voltage on whatever pin you are using for PULSOUT. for example: if the signal voltage on the PULSOUT pin is already at 5 volts then changes to 0 volts, that's called a "negative" pulse because it is changing from a more positive voltage to a "less" positive voltage. What it does NOT mean is the voltage is a negative value, it's just talking about the direction of "Change" in voltage. Does that help?
  • IroneIrone Posts: 116
    edited 2012-10-01 19:52
    Hello,

    I reread the help file on toggle and found out it changes my variable between a 1 and an 0. It was simple to add one to my clock if the twister was 1 and subtract one if it was not. The problem now is my variable is a nib and it goes to 15. I wish to run a seven segment display (CD4056) which is ancient but I have a few. It comes from the days of decimal coded binary and makes weird displays if you go over nine. Can this be done with the BS2? I am including my code and my schematic

    Toggled-Pin.png
  • SapphireSapphire Posts: 496
    edited 2012-10-01 20:26
    The answer somewhat depends on whether you want the numbers to wrap around or not. Wrap around would be ... 7 8 9 0 1 2 ... or ... 2 1 0 9 8 7 ...

    If you do not want wrap around, the following will stop the count at 0 or 9:
    IF Twister = 1 THEN
      IF clock < 9 THEN clock = clock + 1                        ' increments only if clock is less than 9
    ELSE
      IF clock > 0 THEN clock = clock - 1                        ' decrements only if clock is more than 0
    ENDIF 
    

    However, if you do want wrap around, then the following would work:
    IF Twister = 1 THEN
      IF clock < 9 THEN clock = clock + 1 ELSE clock = 0          ' increments only if clock is less than 9, otherwise sets it to 0
    ELSE
      IF clock > 0 THEN clock = clock - 1 ELSE clock = 9          ' decrements only if clock is more than 0, otherwise sets it to 9
    ENDIF 
    

    I think that the ENDIF should probably be before the DO...LOOP UNTIL (IN7=1) so that it executes for both Twister being 0 or 1.
  • IroneIrone Posts: 116
    edited 2012-10-01 21:09
    Sapphire,

    Thank you so much, the first answer was what I needed. I need this to upgrade my gas grill in the garage. I have nozzles below the cooking grid and an automotive windshield pump bolted to the leg to spray water on the lava rocks. (yes I still use lava rocks) I also noticed you know how to send code. I do remember you need "
    " before and "
    
    " after your program (without the quotation marks) but have forgotten what to do after that.

    Thanks again!
  • IroneIrone Posts: 116
    edited 2012-10-01 21:18
    Hello,

    I think I know what I was doing wrong to attach a code now!
  • SapphireSapphire Posts: 496
    edited 2012-10-01 21:20
    Irone,

    Glad to help. Just don't let any of those CD4056's fall into the fire! Those are great little chips for driving 7-segment displays.

    For posting code, you use the word CODE between square brackets. To end, use /CODE between square brackets.
Sign In or Register to comment.