Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 // PMW3901MB: Optical Motion Tracking Chip reference code. 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 -- 13 Mar. 2018 00020 First release. 00021 */ 00022 00023 #include "mbed.h" 00024 #include "SPIcommFunctions.h" 00025 00026 int main() 00027 { 00028 pc.baud(115200); // Set baud rate to 115200. Remember to sync serial terminal baud rate to the same value. 00029 00030 spi.format(8,3); // Set SPI to 8 bits with inverted polarity and phase-shifted to second edge. 00031 spi.frequency(1000000); // Set frequency for SPI communication. 00032 cs = 1; // Initialize chip select as inactive. 00033 00034 pc.printf("Program START\n\r"); 00035 00036 pc.printf("ID Check: %2X\n\r", readRegister(0x00)); //Checks product ID to make sure communication protocol is working properly. 00037 if(readRegister(0x00) != 0x49) 00038 { 00039 pc.printf("Communication protocol error! Terminating program.\n\r"); 00040 return 0; 00041 } 00042 00043 initializeSensor(); 00044 00045 while(1) 00046 { 00047 //pc.printf("MOTION bit: %2X\n\r", (readRegister(0x02) & 0x80) >> 7); //Prints motion bit for debugging. 1 = motion detected. 0 = no motion detected. 00048 00049 if(readRegister(0x02) & 0x80) 00050 { 00051 grabData(); 00052 printData(); 00053 } 00054 } 00055 }
Generated on Tue Jul 12 2022 18:32:33 by
1.7.2
PMW3901MB | Far-Field Optical Motion Tracking Sensor