Driving

Dependencies:   FSR LIS3DH USBDevice mbed

Fork of MMA8452_Demo by Ivan Rush

Committer:
Ivannrush
Date:
Fri Oct 17 15:40:43 2014 +0000
Revision:
8:46eab8a51f91
Parent:
6:e3100f66ed6a
Child:
9:cbce87f4f21f
Hello World

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ashleymills 0:0c17274c3b7c 1 #include "mbed.h"
ashleymills 0:0c17274c3b7c 2 #include "MMA8452.h"
Ivannrush 8:46eab8a51f91 3 //Using MMA8452 accelerometer. SDA on 28, SCL on 27. Writes gravities to the screen.
Ivannrush 8:46eab8a51f91 4 //Also brightens/dims LEDs 1-3 based on whether or not they are 'level'( 0 Gs)
ashleymills 0:0c17274c3b7c 5
ashleymills 0:0c17274c3b7c 6 Serial pc(USBTX,USBRX);
Ivannrush 8:46eab8a51f91 7 PwmOut led1(LED1);
Ivannrush 8:46eab8a51f91 8 PwmOut led2(LED2);
Ivannrush 8:46eab8a51f91 9 PwmOut led3(LED3);
Ivannrush 8:46eab8a51f91 10 double x, y, z;
ashleymills 1:e9981919b524 11
Ivannrush 8:46eab8a51f91 12 MMA8452 acc(p28, p27, 100000);
ashleymills 1:e9981919b524 13
ashleymills 0:0c17274c3b7c 14 int main() {
Ivannrush 8:46eab8a51f91 15
Ivannrush 8:46eab8a51f91 16 while(1) {
ashleymills 6:e3100f66ed6a 17
Ivannrush 8:46eab8a51f91 18 acc.readXYZGravity(&x,&y,&z);
Ivannrush 8:46eab8a51f91 19 pc.printf("x:%lf y:%lf z:%lf\r\n",x,y,z);
Ivannrush 8:46eab8a51f91 20 led1 = abs(x);
Ivannrush 8:46eab8a51f91 21 led2 = abs(y);
Ivannrush 8:46eab8a51f91 22 led3 = abs(z);
Ivannrush 8:46eab8a51f91 23 wait(.25);
Ivannrush 8:46eab8a51f91 24 }
Ivannrush 8:46eab8a51f91 25 }