Dim MIC_Level As Word
Dim Count As Integer
Sub main()
PRO_BOT128_INIT() 'PRO-BOT128 Setup
ACS_INIT(5) 'ACS setup / sensitivity 1 To 20 / 1=near / 20 =far
AbsDelay(1000) 'Wait 1Sec.
BLL_ON() 'Back LED left "ON"
BLR_ON() 'Back LED right "ON"
ENC_LED_ON() 'Encoder IR-LEDs "ON"
DRIVE_ON() 'Motor "ON"
Do While True 'Endless Loop
'Drive behaviour
If Count < 3 Then MIC() : End If
If LDR_LEFT() < 300 And LDR_RIGHT() < 300 Then Light() : End If
If ACS_LEFT() = 1 And ACS_RIGHT() = 1 Then Forward() : End If
If ACS_LEFT() = 0 And ACS_RIGHT() = 0 Then Backward() : End If
If ACS_LEFT() = 1 And ACS_RIGHT() = 0 Then Turn_Left() : End If
If ACS_LEFT() = 0 And ACS_RIGHT() = 1 Then Turn_Right() : End If
End While
End Sub
Sub Forward() 'Drive forward
FLL_OFF() 'Front LED left "OFF"
FLR_OFF() 'Front LED right "OFF"
DRIVE_FORWARD(7) 'Drive forward, speed 1 To 10 : Value = 7
DELAY_MS(150) 'Wait 150ms
End Sub
Sub Backward() 'Drive backward
FLL_ON() 'Front LED left "ON"
FLR_ON() 'Front LED right "ON"
GO_TURN(-15,0,150) 'Backward 15cm, Speed = 150
GO_TURN(0,60,150) 'Turn right, speed = 150
End Sub
Sub Turn_Left() 'Turn left
FLL_OFF() 'Front LED left "OFF"
FLR_ON() 'Front LED right "ON"
GO_TURN(0,-45,150) 'Turn left, Speed = 150
End Sub
Sub Turn_Right() 'Turn right
FLL_ON() 'Front LED left "ON"
FLR_OFF() 'Front LED right "OFF"
GO_TURN(0,45,150) 'Turn right, Speed = 150
End Sub
Sub MIC()
MIC_Level = GetAdc(3) 'Read soundlevel
If MIC_Level > 700 Then 'If the Soundlevel larger As 650 Then
Count = Count + 1 'Set Count + 1
End If
End Sub
Sub Light()
FLL_ON()
FLR_ON()
BLL_ON()
BLR_ON()
End Sub
Lesezeichen