Shop OBEX P1 Docs P2 Docs Learn Events
Question about RPS. — Parallax Forums

Question about RPS.

ExilictExilict Posts: 31
edited 2004-11-09 13:55 in BASIC Stamp
I am looking to write the following code, however I am stuck.· I know you guys will beat it out in second, so I figgured I would ask.

I have a switch, I need to measure how many times a second the switch is being activated. But it needs to have 2 different levels.

If the switch is activating 1· - 6 times a second I need to set a variable to 1
If the switch is activating 7+ times a second I need to set a variable to 3

However it needs to constantally monitor the switches/second.· If it drops under 7 it needs to change the var to 1, if it goes above 7 it needs to change the var to 3

The variable will be used in a loop to control the number of times a solenoid is activated.

Thanks,
·· Chris

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-11-09 03:11
    Give this a go:

    COUNT switch, 1000, swIns
    IF (swIns > 6) THEN 
      rate = 3
    ELSE
      rate = 1
    ENDIF
    


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • ExilictExilict Posts: 31
    edited 2004-11-09 03:36
    Jon,
    ·· Will that freeze the program for the entire second?

    I am also working on a switch / solenoid program.· Every time the switch is pulled I need it to activate the·solenoid 1 time, however if the switch is pulled more then·7 times a second I want it to activate 3·times for every pull.· The·switch and the pull need to operate·together.

    The variable controls how many times the·"Activate" routine activates inside of a loop.

    Thanks
    ·· Chris·

    Post Edited (Exilict) : 11/9/2004 3:39:38 AM GMT
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2004-11-09 06:32
    Chris -

    Wait unitl you get his BILL! smile.gif

    Bruce
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-11-09 13:55
    I'm not even sure Miss Cleo could help here.... but let me keep trying.

    Can one measure the time between one trigger pull and the next, then work from there? -- assuming that the trigger pulls are going to be at a fairly regular rate.· If the trigger pulls are about 142 ms or less apart, that would be seven pulls per second.

    GOSUB Reset_Timer
    DO
      GOSUB Wait_For_Trigger
      GOSUB Get_Timer
      GOSUB Reset_Timer
      IF (timer > 142) THEN
        rate = 3
      ELSE
        rate = 1
      ENDIF
    LOOP
    



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
Sign In or Register to comment.