Shop OBEX P1 Docs P2 Docs Learn Events
How would I say this.?. — Parallax Forums

How would I say this.?.

bobsmithbobsmith Posts: 36
edited 2004-11-04 22:53 in BASIC Stamp
I am programming code for a paintball· marker.· What i want the code to be like is·

each time the microswitch is activated that equal 1.3 times the solenoid is cycled but it only cycles once b/c 1.3 isn't a integer.· But say the microswitch is activated 5 times in a row it times those 5 activations by 1.3 which equals 6.5 but it only cycles the solenoid 6 times b/c 6.5 isn't an integer

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-11-01 22:01
    Are you saying that you want to activate the solenoid more times than the switch? How will you know?...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • bobsmithbobsmith Posts: 36
    edited 2004-11-01 22:06
    yes
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-11-01 22:12
    My questions stands then: In a given period, how do you know how many times to activate the switch until you've actually monitored the switch input? If you're going to monitor and then shoot, you will end up having round-off errors until your trigger input count is great enough to overcome the math.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • bobsmithbobsmith Posts: 36
    edited 2004-11-02 14:49
    what I am trying to create is a more complex and thought out way and method of debounce
  • allanlane5allanlane5 Posts: 3,815
    edited 2004-11-02 16:00
    You need to distinguish your 'sampling' of the button state ("microswitch is activated") from the number of times the user actually pulls the trigger (currently, "the microswitch is activated" again?).

    I don't think the user can pull the trigger faster than every 100 mSec -- but maybe that's not your problem?

    The statement "each time the microswitch is activated that equal 1.3 times the solenoid" doesn't make sense to me. You need to put in some more words -- like "equal 1.3 times the length of time the solenoid is active" or something like that.

    The way you've stated the problem so far, it is very hard to see what you are asking.
  • bobsmithbobsmith Posts: 36
    edited 2004-11-02 21:41
    See this is what a normal operation code would look like.

    SYMBOL trigger = 1
    SYMBOL solenoid = 2

    if trigger = 1 then

    high solenoid
    pause 40
    low solenoid
    pause 40

    end

    but I want it to say:
    ____________________________________

    if trigger is pulled then

    cycle soleniod 1.3 times each time the trigger is pulled, but only cycle the integer part of the digit.

    ______________________________________________

    Example:

    If trigger is pulled 6 times in a row
    then the solenoid cycles 7 times

    (6 * 1.3 = 7.8 but we make 7.8 be 7)
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-11-02 22:03
    When do you want to cycle the solenoid? After each press? After a group of presses? After some time window? Your question is still very confusing as it is like saying, "I want you to give me 1.3 times the number of dollars I'm about to hand you..." Unless I know how many dollars you're about to hand me, what number am I suppused to multiply 1.3 by?....

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • bobsmithbobsmith Posts: 36
    edited 2004-11-03 15:18
    after each press.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2004-11-03 15:50
    bobsmith said...
    See this is what a normal operation code would look like.

    SYMBOL trigger = 1
    SYMBOL solenoid = 2

    if trigger = 1 then

    high solenoid
    pause 40
    low solenoid
    pause 40

    end

    but I want it to say:
    ____________________________________

    if trigger is pulled then

    cycle soleniod 1.3 times each time the trigger is pulled, but only cycle the integer part of the digit.

    ______________________________________________

    Example:

    If trigger is pulled 6 times in a row
    then the solenoid cycles 7 times

    (6 * 1.3 = 7.8 but we make 7.8 be 7)
    Bob -

    If you multiply your factor (1.3) by 10 then use it in your existing equation:

    ······················ 6 * (10 * 1.3)· or· 6 * 13·

    and then divide your answer by 10 as shown below:

    ····················· ·cycle = 6 x 13 : cycle = cycle / 10

    the decimal part of the answer will be dropped which·appears like what you want it to do, but you·WILL realize the mathematical effect of the .3 value, which is also what it seems like you want to do. This is just the natural effect of the PBASIC "rounding" to an integer value. In effect you are scaling up the interim answer in the first part, and then scaling back down in the second part.

    Regards,

    Bruce Bates
  • bobsmithbobsmith Posts: 36
    edited 2004-11-03 20:08
    put then how do i have the solenoid cycle to the equation
  • Shawn LoweShawn Lowe Posts: 635
    edited 2004-11-04 22:53
    I dont think that will be a problem because the user wont pull the trigger faster than the solenoid will trigger will they?
Sign In or Register to comment.