Reference firmware for PixArt's PMT9123 sensor and evaluation board. "Hello World" and "Library" contain the exact same files. Please import just one of the two into your mBed compiler as a new program and not as a library.
main.cpp
00001 // PMT9123QS: Low Power Right-Angle Optical Track Sensor 00002 // Version: 1.1 00003 // Latest Revision Date: 18 July 2018 00004 // By PixArt Imaging Inc. 00005 // Primary Engineer: Vincent Yeh (PixArt USA) 00006 00007 // Copyright [2018] [Vincent Yeh] 00008 // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: 00009 // http://www.apache.org/licenses/LICENSE-2.0 00010 00011 00012 /* 00013 //======================= 00014 //Revision History 00015 //======================= 00016 Version 1.1 -- 18 July 2018 00017 Added apache license notice. 00018 00019 Version 1.0 -- 9 Apr. 2018 00020 First release. 00021 */ 00022 00023 #include "mbed.h" 00024 #include "registerArrays.h" 00025 #include "I2CcommFunctions.h" 00026 00027 int main() 00028 { 00029 pc.baud(115200); // Set baud rate to 115200. Remember to sync serial terminal baud rate to the same value. 00030 i2c.frequency(400000); // Set frequency for I2C communication. 00031 startup(); 00032 00033 pc.printf("Program START\n\r"); 00034 pc.printf("ID Check: %2X\n\r", readRegister(0x00)); //Checks product ID to make sure communication protocol is working properly. 00035 if(readRegister(0x00) != 0x41) 00036 { 00037 pc.printf("Communication protocol error! Terminating program.\n\r"); 00038 return 0; 00039 } 00040 00041 initialize(); 00042 load(optimize, optimize_size); //Load register settings from the "initialize" array 00043 00044 while(1) 00045 { 00046 //pc.printf("MOTION bit: %2X\n\r", (readRegister(0x02) & 0x80) >> 7); //Prints motion bit for debugging. 1 = motion detected. 0 = no motion detected. 00047 00048 if(readRegister(0x02) & 0x80) 00049 { 00050 grabData(); 00051 printData(); 00052 } 00053 } 00054 }
Generated on Fri Jul 15 2022 11:19:28 by 1.7.2