PixArt Optical Track Sensor, OTS, demo program for P5101 sensor with OTS library v1.1. Imported and modified from P9130 demo program. Initial release v1.0.

Dependencies:   Pixart_OTS

Fork of OTS_P5101_Demo by Hill Chen

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2018 ARM Limited
00003  * SPDX-License-Identifier: Apache-2.0
00004  */
00005 
00006 /* PAA5101EW: Optical Tracking Sensor.
00007  * By PixArt Imaging Inc.
00008  * Primary Engineer: Hill Chen (PixArt USA)
00009  *
00010  * License: Apache-2.0; http://www.apache.org/licenses/LICENSE-2.0
00011  */
00012  
00013 /* Demo Code Revision History
00014  * V1.0: March 26, 2019
00015  * First release.
00016  */
00017 
00018 #include "mbed.h"
00019 #include "Pixart_OTS.h"
00020 
00021 Serial  pc(USBTX, USBRX);
00022 SPI spi(p23, p24, p25); //mosi, miso, sclk
00023 DigitalOut cs(p22);     //chip select
00024 DigitalOut ldp_enl_pin(p20);//laser diode control, low enable
00025 
00026 static const Pixart_OTS_Model OTS_MODEL = PIXART_OTS_MODEL_5101;
00027 
00028 int main()
00029 {
00030     pc.baud(115200);
00031 
00032     Pixart_OTS *pixart_ots = create_pixart_ots(OTS_MODEL, pc, spi, cs, ldp_enl_pin);
00033 
00034     if (!pixart_ots)
00035     {
00036         pc.printf("\r\n\n Not on library support list %d", OTS_MODEL);
00037         while (true);
00038     }
00039 
00040     bool result = pixart_ots->sensor_init();
00041 
00042     if (result)
00043     {
00044         pc.printf("\r\n\n %s %s initialization successfully\r\n", PRODUCT, pixart_ots->get_model().c_str());
00045     }  
00046     else
00047     {
00048         pc.printf("\r\n\n %s %s fail on initialization", PRODUCT, pixart_ots->get_model().c_str());
00049         while (true);
00050     }
00051 
00052     while (true) {
00053 #ifndef USE_CALLBACK           
00054         pixart_ots->periodic_callback();
00055         wait_ms(250);
00056 #endif        
00057     }
00058 }
00059