Shop OBEX P1 Docs P2 Docs Learn Events
Sonar Code Question — Parallax Forums

Sonar Code Question

AImanAIman Posts: 531
edited 2006-10-10 21:50 in BASIC Stamp
Heres my code:

Sonar1 PIN 1········
Sonar2 PIN 3········
Sonar3 PIN 5
Sonar4 PIN 7········
Sonar5 PIN 9
···
IsHigh CON 1
IsLow CON 0
Distance VAR Word
Trigger···· CON···· 1
DO WHILE Override <> STOP···· ' Override comes from different BS2
· DO
····· GOSUB Sonar1
····· GOSUB Sonar2
····· GOSUB Sonar3
····· GOSUB Sonar4
····· GOSUB Sonar5
· LOOP
LOOP

getsonar1:
· Sonar1 = IsLow
· PULSOUT Sonar1, Trigger
· PULSIN· Sonar1, IsHigh, distance
· distance = distance / 29
· RETURN

getsonar2:
· Sonar2 = IsLow
· PULSOUT Sonar2, Trigger
· PULSIN· Sonar2, IsHigh, distance
· distance = distance / 29
· RETURN

getsonar3:
· Sonar3 = IsLow
· PULSOUT Sonar3, Trigger
· PULSIN· Sonar3, IsHigh, distance
· distance = distance / 29
· RETURN

getsonar4:
· Sonar4 = IsLow
· PULSOUT Sonar4, Trigger
· PULSIN· Sonar4, IsHigh, distance
· distance = distance / 29
· RETURN

getsonar5:
· Sonar5 = IsLow
· PULSOUT Sonar5, Trigger
· PULSIN· Sonar5, IsHigh, distance
· distance = distance / 29
· RETURN

I know I am missing something very simple but can't remember what (I have been up way to long). Any help would be appreciated.

Comments

  • Tom WalkerTom Walker Posts: 509
    edited 2006-10-10 13:37
    Just a quick first pass without the IDE handy...
    1) No STAMP and PBASIC definitions
    2) Override and STOP not defined
    3) Variable names inconsistent (Distance vs. distance)
    4) It may read fine all day once you correct the above, but it doesn't DO anything with the distance variable.

    I'm guessing that this is not REALLY all of your code [noparse];)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Truly Understand the Fundamentals and the Path will be so much easier...
  • AImanAIman Posts: 531
    edited 2006-10-10 14:06
    Its just the part dealing with the sonar, the whole code would be more then people would want to read through for this question. ·The distance I missed, the stamp and Pbasic definitions are·the first two lines of the program - my habit is to ALWAYS put them there. Override is the variable for stopping the sonar execution coming from a different BS2.

    By the way, the sonar being used is the SensComp 6500. The 6500 has a range of up to 35 feet, a freq of 50 khz and requires two pins.

    Thanks for the help Tom.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-10-10 15:27
    Hello,
    ·
    ·· It might also help to be more clear in your question.· The subject was, “Sonar Code Question”, but the only thing you asked was if you were missing anything.· Without knowing what you wanted it to do in the first place and without the complete code there is really no way to know what you are missing.· In the future it would help to state that this is a code fragment and what exactly it is doing or not doing so we may attempt to see why.· Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • Paul Sr.Paul Sr. Posts: 435
    edited 2006-10-10 16:28
    GOSUB to PINS????
  • Tom WalkerTom Walker Posts: 509
    edited 2006-10-10 20:42
    Excellent point. Your GOSUBs should go to getsonar1, getsonar2, etc...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Truly Understand the Fundamentals and the Path will be so much easier...
  • FranklinFranklin Posts: 4,747
    edited 2006-10-10 21:50
    You can attach your code so others can load it into the ide and better see what is happening.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
Sign In or Register to comment.