Sonar Code Question
AIman
Posts: 531
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.
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
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...
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.
·
·· 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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Truly Understand the Fundamentals and the Path will be so much easier...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen