![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
This is an export for Dan
Fork of ADXL345_HelloWorld by
main.cpp@1:ba867c823c0b, 2016-04-14 (annotated)
- Committer:
- atravieso
- Date:
- Thu Apr 14 18:51:37 2016 +0000
- Revision:
- 1:ba867c823c0b
- Parent:
- 0:9e92575dece6
Export for Dan
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aberk | 0:9e92575dece6 | 1 | #include "ADXL345.h" |
aberk | 0:9e92575dece6 | 2 | |
aberk | 0:9e92575dece6 | 3 | ADXL345 accelerometer(p5, p6, p7, p8); |
aberk | 0:9e92575dece6 | 4 | Serial pc(USBTX, USBRX); |
aberk | 0:9e92575dece6 | 5 | |
aberk | 0:9e92575dece6 | 6 | int main() { |
aberk | 0:9e92575dece6 | 7 | |
aberk | 0:9e92575dece6 | 8 | int readings[3] = {0, 0, 0}; |
aberk | 0:9e92575dece6 | 9 | |
aberk | 0:9e92575dece6 | 10 | pc.printf("Starting ADXL345 test...\n"); |
aberk | 0:9e92575dece6 | 11 | pc.printf("Device ID is: 0x%02x\n", accelerometer.getDevId()); |
aberk | 0:9e92575dece6 | 12 | |
aberk | 0:9e92575dece6 | 13 | //Go into standby mode to configure the device. |
aberk | 0:9e92575dece6 | 14 | accelerometer.setPowerControl(0x00); |
aberk | 0:9e92575dece6 | 15 | |
aberk | 0:9e92575dece6 | 16 | //Full resolution, +/-16g, 4mg/LSB. |
aberk | 0:9e92575dece6 | 17 | accelerometer.setDataFormatControl(0x0B); |
aberk | 0:9e92575dece6 | 18 | |
atravieso | 1:ba867c823c0b | 19 | //3.2kHz data rate. Changed from 3.2k to 25Hz |
atravieso | 1:ba867c823c0b | 20 | accelerometer.setDataRate(ADXL345_25HZ); |
aberk | 0:9e92575dece6 | 21 | |
aberk | 0:9e92575dece6 | 22 | //Measurement mode. |
aberk | 0:9e92575dece6 | 23 | accelerometer.setPowerControl(0x08); |
aberk | 0:9e92575dece6 | 24 | |
aberk | 0:9e92575dece6 | 25 | while (1) { |
aberk | 0:9e92575dece6 | 26 | |
aberk | 0:9e92575dece6 | 27 | wait(0.1); |
aberk | 0:9e92575dece6 | 28 | |
aberk | 0:9e92575dece6 | 29 | accelerometer.getOutput(readings); |
aberk | 0:9e92575dece6 | 30 | |
aberk | 0:9e92575dece6 | 31 | //13-bit, sign extended values. |
atravieso | 1:ba867c823c0b | 32 | pc.printf("X:%i, Y:%i, Z:%i\r\n", (int16_t)readings[0], (int16_t)readings[1], (int16_t)readings[2]); |
aberk | 0:9e92575dece6 | 33 | |
aberk | 0:9e92575dece6 | 34 | } |
aberk | 0:9e92575dece6 | 35 | |
aberk | 0:9e92575dece6 | 36 | } |