Mini Project 10: Displaying stuff from day 7

Dependencies:   DmTouch_UniGraphic UniGraphic mbed

Committer:
ezimmerman17
Date:
Tue Jan 17 19:12:33 2017 +0000
Revision:
6:b196b0a8f337
Parent:
0:1ebe73e062a7
Child:
7:ee7f2c33d45d
messed with accelerometer file stuff;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
swescott17 0:1ebe73e062a7 1 #include "acceler_sensor.h"
swescott17 0:1ebe73e062a7 2 DigitalOut led3(LED3);
swescott17 0:1ebe73e062a7 3
ezimmerman17 6:b196b0a8f337 4 void configure_acceleration(void){
swescott17 0:1ebe73e062a7 5
swescott17 0:1ebe73e062a7 6 const int address = 0x53 << 1; // set 'address' to
swescott17 0:1ebe73e062a7 7 i2c_port.start();
swescott17 0:1ebe73e062a7 8 i2c_port.write(address);
swescott17 0:1ebe73e062a7 9 i2c_port.write(0x1D); //to set the Tap Threshold
swescott17 0:1ebe73e062a7 10 i2c_port.write(0x50 << 2);
swescott17 0:1ebe73e062a7 11 i2c_port.stop();
swescott17 0:1ebe73e062a7 12 wait(0.01);
swescott17 0:1ebe73e062a7 13
swescott17 0:1ebe73e062a7 14 i2c_port.start();
swescott17 0:1ebe73e062a7 15 i2c_port.write(address);
swescott17 0:1ebe73e062a7 16 i2c_port.write(0x21);//set Tap Duration
swescott17 0:1ebe73e062a7 17 i2c_port.write(0x0A);
swescott17 0:1ebe73e062a7 18 i2c_port.stop();
swescott17 0:1ebe73e062a7 19 wait(0.01);
swescott17 0:1ebe73e062a7 20
swescott17 0:1ebe73e062a7 21 i2c_port.start();
swescott17 0:1ebe73e062a7 22 i2c_port.write(address);
swescott17 0:1ebe73e062a7 23 int temp[2] = {0x22, 0x05};
swescott17 0:1ebe73e062a7 24 i2c_port.write(temp[0]);//set Tap Gap
swescott17 0:1ebe73e062a7 25 i2c_port.write(temp[1]);
swescott17 0:1ebe73e062a7 26 i2c_port.stop();
swescott17 0:1ebe73e062a7 27 wait(0.01);
swescott17 0:1ebe73e062a7 28
swescott17 0:1ebe73e062a7 29 i2c_port.start();
swescott17 0:1ebe73e062a7 30 i2c_port.write(address);
swescott17 0:1ebe73e062a7 31 i2c_port.write(0x23);//set Tap Window
swescott17 0:1ebe73e062a7 32 i2c_port.write(0xFF);
swescott17 0:1ebe73e062a7 33 i2c_port.stop();
swescott17 0:1ebe73e062a7 34 wait(0.01);
swescott17 0:1ebe73e062a7 35
swescott17 0:1ebe73e062a7 36 i2c_port.start();
swescott17 0:1ebe73e062a7 37 i2c_port.write(address);
swescott17 0:1ebe73e062a7 38 i2c_port.write(0x2A);//set Tap Axis
swescott17 0:1ebe73e062a7 39 i2c_port.write(0x07);
swescott17 0:1ebe73e062a7 40 i2c_port.stop();
swescott17 0:1ebe73e062a7 41 wait(0.01);
swescott17 0:1ebe73e062a7 42
swescott17 0:1ebe73e062a7 43 i2c_port.start();
swescott17 0:1ebe73e062a7 44 i2c_port.write(address);
swescott17 0:1ebe73e062a7 45 i2c_port.write(0x2E);//set interupt Enable
swescott17 0:1ebe73e062a7 46 i2c_port.write(0x20|0x40);
swescott17 0:1ebe73e062a7 47 i2c_port.stop();
swescott17 0:1ebe73e062a7 48 wait(0.01);
swescott17 0:1ebe73e062a7 49
swescott17 0:1ebe73e062a7 50 i2c_port.start();
swescott17 0:1ebe73e062a7 51 i2c_port.write(address);
swescott17 0:1ebe73e062a7 52 i2c_port.write(0x2F);//set interupt map
swescott17 0:1ebe73e062a7 53 i2c_port.write(0x20|0x40);
swescott17 0:1ebe73e062a7 54 i2c_port.stop();
swescott17 0:1ebe73e062a7 55 wait(0.01);
swescott17 0:1ebe73e062a7 56
swescott17 0:1ebe73e062a7 57 i2c_port.start();
swescott17 0:1ebe73e062a7 58 i2c_port.write(address);
swescott17 0:1ebe73e062a7 59 i2c_port.write(0x2D);//power control register
swescott17 0:1ebe73e062a7 60 i2c_port.write(0x08);//measure mode
swescott17 0:1ebe73e062a7 61 i2c_port.stop();
swescott17 0:1ebe73e062a7 62 wait(0.01);
ezimmerman17 6:b196b0a8f337 63 }
ezimmerman17 6:b196b0a8f337 64
ezimmerman17 6:b196b0a8f337 65 void getacceleration (void){
ezimmerman17 6:b196b0a8f337 66 char buffer[6];
ezimmerman17 6:b196b0a8f337 67 int16_t rawdata[3];
ezimmerman17 6:b196b0a8f337 68 /*acc.write(0x80|0x40|0x32);
ezimmerman17 6:b196b0a8f337 69 for(int i=0; i<= 5; i++)
ezimmerman17 6:b196b0a8f337 70 {
ezimmerman17 6:b196b0a8f337 71 buffer[i]=12c.write(0x00);
ezimmerman17 6:b196b0a8f337 72 //pc.printf("x = %+1.2fg\t", buffer[i]);
ezimmerman17 6:b196b0a8f337 73 }
ezimmerman17 6:b196b0a8f337 74 cs=1;
ezimmerman17 6:b196b0a8f337 75 rawdata[0] = buffer[1]<<8 | buffer[0];
ezimmerman17 6:b196b0a8f337 76 rawdata[1] = buffer[3]<<8 | buffer[2];
ezimmerman17 6:b196b0a8f337 77 rawdata[2] = buffer[5]<<8 | buffer[4];
ezimmerman17 6:b196b0a8f337 78 data[0] = rawdata[0];
ezimmerman17 6:b196b0a8f337 79 data[1] = rawdata[1];
ezimmerman17 6:b196b0a8f337 80 float x = data[0];
ezimmerman17 6:b196b0a8f337 81 float y = data[1];
ezimmerman17 6:b196b0a8f337 82 pc.printf("x = %+1.2fg\t y = %+1.2fg\n\r", rawdata[0],rawdata[1]); Just grabbed from SPI code. Not formatted right*/
ezimmerman17 6:b196b0a8f337 83
ezimmerman17 6:b196b0a8f337 84 }