Hi Vali,
Would you share the project files? (sch and b4r code)? Thanks
Hi
I am glad that this project has been noticed
If you want photos or videos from the project, give me an email address and I will send them
I will be happy if you visit my telegram chanel with address t.me/basic_for_arduino
#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 300
#End Region
'Ctrl+Click to open the C code folder: ide://run?File=%WINDIR%\System32\explorer.exe&Args=%PROJECT%\Objects\Src
Sub Process_Globals
Public RedLed As Pin
Public GreenLed As Pin
Public Buzzer As Pin
Public Serial1 As Serial
Public Radarservo As Servo
Public MissileServo As Servo
Public Radarservo1Pin As Pin
Public MissileServopin As Pin
Public angle As Byte
Public FirstAngle As Byte
Public Ultra As SRF04
Public TargetSpace As Int
Public maxSpace As Int=80
Public RadarDelay As Byte=10
Public TargetDetect As Boolean
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
RedLed.Initialize(2,RedLed.MODE_OUTPUT)
GreenLed.Initialize(3,GreenLed.MODE_OUTPUT)
Buzzer.Initialize(10,Buzzer.MODE_OUTPUT)
Radarservo1Pin.Initialize(7,Radarservo1Pin.MODE_OUTPUT)
MissileServopin.Initialize(6,MissileServopin.MODE_OUTPUT)
Radarservo.Attach(7)
MissileServo.Attach(6)
TestSystem
Log("Servo milisecound is ",Radarservo.ReadMicroseconds)
FirstAngle=Radarservo.read
Log("Curreny angle = ",FirstAngle)
Radarservo.Write(-1 *angle)
Ultra.Initialize(8,9)
NormalCase
Do While True
TargetDetect=False
angle=45
Do While angle<=135 And angle>=45
TargetSpace=Ultra.GetDistance
Log("D=",angle, "-R=",TargetSpace)
If TargetSpace<maxSpace Then
TargetDetect=True
WarCase
LockTarget
End If
Radarservo.Write(angle)
angle=angle+1
Delay(RadarDelay)
Loop
angle=135
Do While angle <=135 And angle>=45
TargetSpace=Ultra.GetDistance
Log("D=",angle, "-R=",TargetSpace )
If TargetSpace<maxSpace Then
TargetDetect=True
WarCase
LockTarget
End If
Radarservo.Write(angle)
angle=angle-1
Delay(RadarDelay)
Loop
If TargetDetect=True Then
WarCase
Else
NormalCase
End If
Loop
Log("finished")
End Sub
public Sub WarCase
RedLed.DigitalWrite(True)
GreenLed.DigitalWrite(False)
Buzzer.DigitalWrite(True)
End Sub
public Sub NormalCase
RedLed.DigitalWrite(False)
GreenLed.DigitalWrite(True)
Buzzer.DigitalWrite(False)
End Sub
public Sub LockTarget
MissileServo.Write(angle)
End Sub
public Sub TestSystem
GreenLed.DigitalWrite(True)
Delay(1000)
GreenLed.DigitalWrite(False)
RedLed.DigitalWrite(True)
Delay(1000)
RedLed.DigitalWrite(False)
Buzzer.DigitalWrite(True)
Delay(1000)
Buzzer.DigitalWrite(False)
For i=0 To 180
MissileServo.Write(i)
Delay(10)
Next
For i=180 To 0 Step -1
MissileServo.Write(i)
Delay(10)
Next
Delay(1000)
MissileServo.Write(90)
End Sub