| GP2D12 to OOPic Example Last Modified: 2006-10-25 | | |
| Acroname Robotics | PDF webpage version | ||
| ![]() Introduction In this example, an OOPic microcontroller uses a Sharp GP2D12 detector to measure distances to obstacles. The program converts the analog voltage at the output of the GP2D12 detector to an 8-bit value. The program turns on an LED when this value exceeds a threshold. Circuit Schematic The following schematic assumes the OOpic has an appropriate power supply. The typical current draw of a GP2D12 is 33ma so it can be powered by the OOPic's 100ma onboard regulator. The pin selections match those in the source code listed below. This circuit is very simple. All that is required is hooking up an LED and directly wiring the Sharp GP2D12 output to one of the four OOPic pins that can be used for analog-to-digital conversion. See a similar Sharp GP2D12 Project with a more detailed discussion at the OOPic Web Site . ![]() Source Code This code uses BASIC syntax. It runs with version 3.0.1 of the OOpic compiler and version A.1.7 of the OOpic chip. ' Filename: GP2D12-2.osc
' This program reads the Sharp GP2D12 sensor
' It demonstrates the use of an oA2D object
' and an oDio1 object. In this program, an LED
' turns on when an object is too close to the
' GP2D12 sensor.
dim bitTest as new oDio1
dim adc1 as new oA2D
sub main()
bitTest.Ioline = 9
bitTest.Direction = cvOutput
bitTest.value = 0
Oopic.ExtVRef=0
adc1.ioline=1
adc1.operate=cvtrue
do
if adc1.value > 100 then
bitTest.value=1
else
bitTest.value=0
end if
loop
end sub
Revision History:
| |||
| voice: 720-564-0373, email: sales@acroname.com, address: 4822 Sterling Dr., Boulder CO, 80301-2350, privacy © Copyright 1994-2010 Acroname, Inc., Boulder, Colorado. All rights reserved. |