Created
February 27, 2017 09:59
-
-
Save flyboy74/bd1c31e6410cae321444efd6e1abda80 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'initilize the 2 ultra sonic sensors in port 1 and 4 in mode 0 | |
Sensor.SetMode(1,0) | |
Sensor.SetMode(4,0) | |
'initilize varibles | |
distance = 800 | |
dir = "left" | |
speed = 20 | |
'play the recorded into sound file, this canm be removed if you don't have a recorded intro sound file | |
Speaker.Play(100,"Sounds/Robo Dog/Intro Dog") | |
Speaker.Wait() | |
'All sub routines are found at the bottom of the code after the main body | |
'Main program running in a endless loop | |
While "true" | |
'check distance in both sensors | |
eyes() | |
'if nothing seen in either sensor then turn and look for something | |
If left > distance And right > distance Then | |
look() | |
'if something is really close then play happy bark and wag tail | |
Elseif left < 300 Or right < 300 Then | |
Speaker.Play(100,"Sounds/Animals/Dog bark 2") | |
Motor.Start("D", 50) | |
'wait till there isn't somthing close in front of eyes then stop wagging tail | |
While left < 300 Or right < 300 | |
eyes() | |
EndWhile | |
Motor.Stop("D","false") | |
''if see something in right but nothing in left then move forward and to the right and set last seen direction to right | |
ElseIf left > distance And right < distance Then | |
Motor.Move("B", 70, 30,"false") | |
dir = "right" | |
'if something seen in left but nothing in right the move forawrd and to the left and set last seen direction to left | |
ElseiF left < distance And right > distance Then | |
Motor.Move("C",70, 30, "False") | |
dir = "left" | |
'if somthing seen in both eyes then move stright forward at a speed based upon how far away seen object is | |
Elseif left < distance And right < distance And left > 300 And right > 300 Then | |
Motor.Move("BC",(left + right)/15,30,"false") | |
EndIf | |
EndWhile | |
'subroutine to look for person if nothing ion sight | |
Sub look | |
'if last seen directio was right the turn to right else turn to left | |
If dir = "right" Then | |
Motor.Start("B", speed) | |
Motor.Start("C", -speed) | |
Else | |
Motor.Start("B", -20) | |
Motor.Start("C", 20) | |
EndIf | |
'while nothing is seen in either left or right senor | |
While left > distance Or right > distance | |
eyes() | |
EndWhile | |
Motor.Stop("B", "false") | |
Motor.Stop("C", "false") | |
EndSub | |
'subroutine to look at distance in both sensors | |
Sub eyes | |
left = Sensor.ReadRawValue(1,0) | |
right = Sensor.ReadRawValue(4,0) | |
EndSub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment