So gehts, so läuft auch mein roboter rumZitat von Daveler
Dim Sonardistance As Word 'entfernung vom objekt 3-10965cm
Sonardistance = Sonarread(sonaraddr , 2)
Declare Function Sonarread(byval I2cnode As Byte , Byval Loc As Byte) As Word ' sonar auslesen
Declare Sub Sonarping(byval I2cnode As Byte , Byval Loc As Byte , Byval Value As Byte) 'echo aussenden
'#################### sonarsteuerung ###########################################
Sub Sonarinit
I2cwbyte &HE0
I2cwbyte 1 'verstärkungsregister
I2cwbyte 1 'unempfindlich
I2cstop
Waitms 65
End Sub Sonarinit
Sub Sonarping(byval I2cnode As Byte , Loc As Byte , Value As Byte)
Waitms 25
I2cstart
I2cwbyte 0
I2cwbyte 0
I2cwbyte 81
I2cstop
Waitms 55
End Sub Sonarping
Function Sonarread(byval I2cnode As Byte , Loc As Byte) As Word
Waitms 25
Local Lsb As Byte
Local Msb As Byte
I2cstart
I2cwbyte I2cnode
I2cwbyte Loc
I2cstart
Incr I2cnode 'lesen immer eine adresse höher wie schreiben
I2cwbyte I2cnode
I2crbyte Msb , Ack
I2crbyte Lsb , Nack
I2cstop
Waitms 25
Sonarread = Makeint(lsb , Msb)
End Function
Lesezeichen