adsense

2012-05-02

嵌入式 三個交叉點


第一個交叉點 畢一聲
第二個 轉180
第三個 停下來 畢三聲


'InnobotLineTracker.inb: Innobot Follow The Black Line
#DEFINE R_NORMAL_SPEED 80     'Set Innobot Normal Speed
#DEFINE L_NORMAL_SPEED 70
#DEFINE ERROR_1     90 'Define Error for each Sensor Value
#DEFINE ERROR_2     60
#DEFINE ERROR_3     40
#DEFINE ERROR_4     0
#DEFINE ERROR_5   -40
#DEFINE ERROR_6   -60
#DEFINE ERROR_7   -80
Const Frequency As Word = 1047
Sub Main()
Dim I,Sensor As Byte
Dim R, L, Err,j,k,a,b As Integer    
Low 10: Low 11

DO
Sensor=(In(7)<<2)+(In(8)<<1)+In(9) 'Combine L,M,R Sensor State to Sensor Variable
Sensor=(~Sensor) AND &B00000111
Select Sensor 'Select Modified Parameter By Sensor
Case &B100
Err = ERROR_2
Case &B110
Err = ERROR_3
      Case &B010
Err = ERROR_4
        Case &B011
Err = ERROR_5
        Case &B001
Err = ERROR_6
        Case &B000
If Err<1 Then
    Err = ERROR_7
Elseif Err>1 Then
    Err = ERROR_1
End If
Case &B111
            Err = ERROR_4
j+=1
Select j
Case 1
    Sound(12,200,1047)
    Case 2
    For k=1 To 38*2 'U Turn'
  Pulseout(10,250):Pulseout(11,250)
Sound(12,16,1047)
Next k
  Case 3
    For a=0 To 3 Step a+1
  Sound(12,400,768)
    Next a
    PAUSE(1000000)
  End Select
         End Select
R = (300+R_NORMAL_SPEED) + Err
        L = (300-L_NORMAL_SPEED) + Err
    Pulseout(10,L): Pulseout(11,R): PAUSE(16) 'Output control Signal
Loop
End Sub

沒有留言:

張貼留言