Example program with the MMA7660 I2C accelerometer of the mbed application shield.

Dependencies:   MMA7660 mbed

Committer:
screamer
Date:
Fri Feb 13 09:46:19 2015 +0000
Revision:
4:f7eb0d4af69c
Parent:
3:2a332c2b54f4
Update mbed library.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
screamer 3:2a332c2b54f4 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
screamer 3:2a332c2b54f4 2 *
screamer 3:2a332c2b54f4 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
screamer 3:2a332c2b54f4 4 * and associated documentation files (the "Software"), to deal in the Software without
screamer 3:2a332c2b54f4 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
screamer 3:2a332c2b54f4 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
screamer 3:2a332c2b54f4 7 * Software is furnished to do so, subject to the following conditions:
screamer 3:2a332c2b54f4 8 *
screamer 3:2a332c2b54f4 9 * The above copyright notice and this permission notice shall be included in all copies or
screamer 3:2a332c2b54f4 10 * substantial portions of the Software.
screamer 3:2a332c2b54f4 11 *
screamer 3:2a332c2b54f4 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
screamer 3:2a332c2b54f4 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
screamer 3:2a332c2b54f4 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
screamer 3:2a332c2b54f4 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
screamer 3:2a332c2b54f4 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
screamer 3:2a332c2b54f4 17 */
screamer 3:2a332c2b54f4 18
screamer 0:494536c26f91 19 #include "mbed.h"
screamer 0:494536c26f91 20 #include "MMA7660.h"
screamer 0:494536c26f91 21
screamer 0:494536c26f91 22 MMA7660 MMA(D14, D15);
screamer 0:494536c26f91 23 Serial pc(USBTX, USBRX);
screamer 0:494536c26f91 24
screamer 0:494536c26f91 25 int main()
screamer 0:494536c26f91 26 {
screamer 0:494536c26f91 27 if (!MMA.testConnection()) {
screamer 0:494536c26f91 28 pc.printf("failed to initialize sensor\r\n");
screamer 0:494536c26f91 29 } else {
screamer 0:494536c26f91 30 pc.printf("mbed application board!\r\n");
screamer 0:494536c26f91 31 }
screamer 0:494536c26f91 32 wait(3);
screamer 0:494536c26f91 33
screamer 0:494536c26f91 34 int i=1;
screamer 0:494536c26f91 35 while(i++) {
screamer 0:494536c26f91 36 pc.printf("x: %f, y: %f, z: %f \r", MMA.x(), MMA.y(), MMA.z());
screamer 0:494536c26f91 37 wait(0.1);
screamer 0:494536c26f91 38 }
screamer 0:494536c26f91 39 }