![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Mini Project 10: Displaying stuff from day 7
Dependencies: DmTouch_UniGraphic UniGraphic mbed
acceler_sensor.cpp
- Committer:
- swescott17
- Date:
- 2017-01-17
- Revision:
- 9:0f4c86e7218a
- Parent:
- 8:bbe3e332fe94
- Child:
- 13:b3637adeaa2a
File content as of revision 9:0f4c86e7218a:
#include "acceler_sensor.h" DigitalOut led3(LED3); void configure_acceleration(void){ const int address = 0x53 << 1; // set 'address' to /*i2c_port.start(); i2c_port.write(address); i2c_port.write(0x1D); //to set the Tap Threshold i2c_port.write(0x50 << 2); i2c_port.stop(); wait(0.01); i2c_port.start(); i2c_port.write(address); i2c_port.write(0x21);//set Tap Duration i2c_port.write(0x0A); i2c_port.stop(); wait(0.01); i2c_port.start(); i2c_port.write(address); int temp[2] = {0x22, 0x05}; i2c_port.write(temp[0]);//set Tap Gap i2c_port.write(temp[1]); i2c_port.stop(); wait(0.01); i2c_port.start(); i2c_port.write(address); i2c_port.write(0x23);//set Tap Window i2c_port.write(0xFF); i2c_port.stop(); wait(0.01); i2c_port.start(); i2c_port.write(address); i2c_port.write(0x2A);//set Tap Axis i2c_port.write(0x07); i2c_port.stop(); wait(0.01); i2c_port.start(); i2c_port.write(address); i2c_port.write(0x2E);//set interupt Enable i2c_port.write(0x20|0x40); i2c_port.stop(); wait(0.01); i2c_port.start(); i2c_port.write(address); i2c_port.write(0x2F);//set interupt map i2c_port.write(0x20|0x40); i2c_port.stop(); wait(0.01); all the above should confige tap functions for accel sensor, so it's unneccesary*/ i2c_port.start(); i2c_port.write(address); i2c_port.frequency(2000000); i2c_port.write(0x2D);//power control register i2c_port.write(0x08);//measure mode i2c_port.stop(); wait(0.01); } void getacceleration (void){ /*const int address = 0x53 << 1; char buffer[6]; int16_t rawdata[3]; i2c_port.write(address); i2c_port.write(0x80|0x40|0x32); for(int i=0; i<= 5; i++) { buffer[i]=12c.write(0x00); //pc.printf("x = %+1.2fg\t", buffer[i]); } cs=1; rawdata[0] = buffer[1]<<8 | buffer[0]; rawdata[1] = buffer[3]<<8 | buffer[2]; rawdata[2] = buffer[5]<<8 | buffer[4]; data[0] = rawdata[0]; data[1] = rawdata[1]; float x = data[0]; float y = data[1]; pc.printf("x = %+1.2fg\t y = %+1.2fg\n\r", rawdata[0],rawdata[1]); //Just grabbed from SPI code. Not formatted right i2c_port.stop(); */ }