Nivedita Singh
/
ACCELEROMETER
ACCELEROMETER coding
main.cpp@0:1f7a1ee1012b, 2019-01-31 (annotated)
- Committer:
- niveditasingh
- Date:
- Thu Jan 31 03:08:12 2019 +0000
- Revision:
- 0:1f7a1ee1012b
accelerometer coding
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
niveditasingh | 0:1f7a1ee1012b | 1 | #include "mbed.h" |
niveditasingh | 0:1f7a1ee1012b | 2 | #include "ADXL345.h" |
niveditasingh | 0:1f7a1ee1012b | 3 | ADXL345 accelerometer (PC_12, PC_11, PC_10, PB_6); |
niveditasingh | 0:1f7a1ee1012b | 4 | DigitalOut greenLed(LED1); |
niveditasingh | 0:1f7a1ee1012b | 5 | Serial pc(USBTX, USBRX); |
niveditasingh | 0:1f7a1ee1012b | 6 | int main() |
niveditasingh | 0:1f7a1ee1012b | 7 | { |
niveditasingh | 0:1f7a1ee1012b | 8 | pc.baud(115200); |
niveditasingh | 0:1f7a1ee1012b | 9 | int readings[3] = {0,0,0}; |
niveditasingh | 0:1f7a1ee1012b | 10 | pc.printf("Accelerometer Started Now\n"); |
niveditasingh | 0:1f7a1ee1012b | 11 | pc.printf("starting ADXL345test \n"); |
niveditasingh | 0:1f7a1ee1012b | 12 | pc.printf("Device ID is : 0x%02x\n",accelerometer.getDevId()); |
niveditasingh | 0:1f7a1ee1012b | 13 | accelerometer.setPowerControl(0x00); |
niveditasingh | 0:1f7a1ee1012b | 14 | accelerometer.setDataFormatControl(0x0B); |
niveditasingh | 0:1f7a1ee1012b | 15 | accelerometer.setDataRate(ADXL345_3200HZ); |
niveditasingh | 0:1f7a1ee1012b | 16 | accelerometer.setPowerControl(0x08); |
niveditasingh | 0:1f7a1ee1012b | 17 | while(1) |
niveditasingh | 0:1f7a1ee1012b | 18 | { |
niveditasingh | 0:1f7a1ee1012b | 19 | greenLed=!greenLed; |
niveditasingh | 0:1f7a1ee1012b | 20 | wait(0.5); |
niveditasingh | 0:1f7a1ee1012b | 21 | accelerometer.getOutput(readings); |
niveditasingh | 0:1f7a1ee1012b | 22 | pc.printf("%d,%d,%d\n",(int16_t)readings[0],(int16_t)readings[1],(int16_t) readings[2]); |
niveditasingh | 0:1f7a1ee1012b | 23 | |
niveditasingh | 0:1f7a1ee1012b | 24 | |
niveditasingh | 0:1f7a1ee1012b | 25 | } |
niveditasingh | 0:1f7a1ee1012b | 26 | } |