background image

 

Figure 8    A2P Board Dimensions 

 

Example Program

 

Example I 

Use  PULSEIN  command  to  read  GP2Y0A02YK  analog  output  data  through  A2P  module. 

Connect  the  GP2Y0A02YK  to  A2P  board.  Then  connect  the  Pulse  Output  pin  of  A2P  to 

BASIC Commander

®

 pin 0 to measure the pulse width. 

 

Sub main() 

Dim temp As Word   

 

Do 

 

 

Pulsein 0,0,temp 

 

 

 

 

‘measure pulse width 

 

 

Debug “Input Signal =”, Temp,CR        ‘display pulse width 

 

 

Pause 100 

 

 

 

 

 

‘wait 100ms   

 

Loop 

 

 

 

 

 

 

 

‘infinite loop 

End Sub 

 

Example II 

Use  GETADC  command  of  I/O  Extender to  measure  GP2Y0A02YK

 

analog  output  directly. 

Set the DIP switch of the I/O Extender module to 0 and connect it to the BASIC Commander

®

Then connect the Analog Output pin of GP2Y0A02YK

 

to I/O Extender pin PA0. 

 

Peripheral MyIO As IOExtenderA @ 0       

 

‘declare module ID as 0 

Sub main()       

Dim temp As Word   

MyIO.SetADC 1     

 

 

 

 

‘start pin PA0 AD conversion 

 

Do 

MyIO.GetADC 0,temp     

 

 

‘read AD value 

 

 

Debug “Input Signal =”, Temp,CR    

‘display AD value 

 

 

Pause 100 

 

 

 

 

 

‘wait 100ms   

 

Loop 

 

 

 

 

 

 

 

‘infinite loop 

End Sub 

Reviews: