Examples | Shop
 
Infrared Object Detector using the Brainstem™ Microcontroller, GP2D02 and DSLCDD2
 
The following example application demonstrates use of the Sharp GP2D02 Infrared Object Detector, DS-LCDD2 IIC LCD and the Brainstem™ microcontroller.
The program uses the newly developed aLCDx.tea library file, which works with the DS-LCDD and DS-LCDD2 range. (The aLCDx.tea can be found here and should be saved in the Brainstem/aSystem file).
The GP2D02 detects any objects in front of it within a range of 10-80cm. This distance is then displayed as a continuously updated number both on the console and LCD screen.
 
Brainstem is a Trademark of Acroname Inc.

 

/* Description: The Sharp GP2D02 Infrared Object Detector and DS-LCDD2
IIC LCD controlled by the Brainstem™ microcontroller.
Created: 17/09/02 Revision 1.00
Written by: Total Robots (Jamie Finnan)
TR006
Brainstem™ is a registered trademark of Acroname Inc
*/
#include <aCore.tea>
#include <aPrint.tea>
#include <aGP.tea>
#define ALCD_ADDR 40 //define LCD address before aLCDx.tea
#include <aLCDx.tea> //This is the DS-LCDD/DS-LCDD2 library
//update available on the examples page.
//********************************************************************
void main()
{
aCore_Sleep (1000); //Small settling delay
aLCDx_String("GP2D02 and DS-LCDD2"); //First Line on start up
aLCDx_Cmd((unsigned char)192); //Command for second Line
aLCDx_String("Example Application"); //Second line on start up
aCore_Sleep(30000); //3 second delay
aLCDx_Cmd(1); //Clear Screen Command
read(); //read subroutine
}
//********************************************************************
void read()
{
int Dis; //int file called Dis
while (1) { //Loop construct

Dis = aGP_ReadGP2D02(); //Read GP2D02 and move to Dis

aPrint_IntDec(Dis); //Write the Dis value to the
aPrint_Char('\n'); //console screen
aLCDx_Cmd (1); //Clear screen command
aLCDx_String(" GP2D02 Distance "); //First Line of screen
aLCDx_Cmd ((unsigned char)192); //Command for second line
aLCDx_String(" Measurement ="); //Second Line of screen
aLCDx_IntDec(Dis); //Write Dis to LCD screen
aLCDx_CharDec('\n'); //second line.
aCore_Sleep(5000); //0.5 sec delay
}
}
//*****************************************************************
//*****************************************************************


Examples | Shop