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.
Fork of MMA8451Q by
MMA8451Q.h
00001 /* Copyright (c) 2010-2011 mbed.org, MIT License 00002 * Copyright (c) 2014 Antonio Quevedo, UNICAMP 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00005 * and associated documentation files (the "Software"), to deal in the Software without 00006 * restriction, including without limitation the rights to use, copy, modify, merge, publish, 00007 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the 00008 * Software is furnished to do so, subject to the following conditions: 00009 * 00010 * The above copyright notice and this permission notice shall be included in all copies or 00011 * substantial portions of the Software. 00012 * 00013 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00014 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00015 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00016 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00017 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00018 */ 00019 00020 #ifndef MMA8451Q_H 00021 #define MMA8451Q_H 00022 00023 #include "mbed.h" 00024 00025 /** 00026 * MMA8451Q accelerometer example, 8-bit samples 00027 * 00028 * @code 00029 * #include "mbed.h" 00030 * #include "MMA8451Q.h" 00031 * 00032 * int main(void) { 00033 * 00034 * MMA8451Q acc(PTE25, PTE24); 00035 * PwmOut rled(LED_RED); 00036 * PwmOut gled(LED_GREEN); 00037 * PwmOut bled(LED_BLUE); 00038 * uint8_t data[3]; 00039 * 00040 * while (true) { 00041 acc.getAccAllAxis(data); 00042 * rled = 1.0 - abs(data[0]/128); 00043 * gled = 1.0 - abs(data[0]/128); 00044 * bled = 1.0 - abs(data[0]/128); 00045 * wait(0.4); 00046 * } 00047 * } 00048 * @endcode 00049 */ 00050 class MMA8451Q 00051 { 00052 public: 00053 /** 00054 * MMA8451Q constructor 00055 * 00056 * @param sda SDA pin 00057 * @param sdl SCL pin 00058 */ 00059 MMA8451Q(PinName sda, PinName scl); 00060 00061 /** 00062 * MMA8451Q destructor 00063 */ 00064 ~MMA8451Q(); 00065 00066 /** 00067 * Get XYZ axis acceleration, 8-bits 00068 * 00069 * @param res array where acceleration data will be stored 00070 */ 00071 void getAccAllAxis(int16_t * res); 00072 00073 private: 00074 I2C m_i2c; 00075 void readRegs(int addr, uint8_t * data, int len); 00076 void writeRegs(uint8_t * data, int len); 00077 00078 }; 00079 00080 #endif
Generated on Sat Jul 16 2022 00:36:29 by
1.7.2
