Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed MPU6050 TextLCD
main.cpp@0:304aaa70b2e8, 2020-05-06 (annotated)
- Committer:
- 20172573073
- Date:
- Wed May 06 03:15:37 2020 +0000
- Revision:
- 0:304aaa70b2e8
acelerometro
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| 20172573073 | 0:304aaa70b2e8 | 1 | #include "mbed.h" |
| 20172573073 | 0:304aaa70b2e8 | 2 | #include "MPU6050.h" |
| 20172573073 | 0:304aaa70b2e8 | 3 | #include "TextLCD.h" |
| 20172573073 | 0:304aaa70b2e8 | 4 | |
| 20172573073 | 0:304aaa70b2e8 | 5 | MPU6050 mpu(A4,A5); |
| 20172573073 | 0:304aaa70b2e8 | 6 | Serial pc(USBTX, USBRX); |
| 20172573073 | 0:304aaa70b2e8 | 7 | TextLCD lcd(PTB18,PTB19,PTC0,PTC4,PTC6,PTC7, TextLCD::LCD16x2 ); |
| 20172573073 | 0:304aaa70b2e8 | 8 | Timer timer; |
| 20172573073 | 0:304aaa70b2e8 | 9 | int gx,gy,gz,ax,ay,az; |
| 20172573073 | 0:304aaa70b2e8 | 10 | long tiempo_prev; |
| 20172573073 | 0:304aaa70b2e8 | 11 | float dt,giro1x,giro1z,giro2x,giro2z,giro1y,giro2y; |
| 20172573073 | 0:304aaa70b2e8 | 12 | |
| 20172573073 | 0:304aaa70b2e8 | 13 | int main() |
| 20172573073 | 0:304aaa70b2e8 | 14 | { |
| 20172573073 | 0:304aaa70b2e8 | 15 | timer.start(); |
| 20172573073 | 0:304aaa70b2e8 | 16 | if(mpu.getID()==0x68) { |
| 20172573073 | 0:304aaa70b2e8 | 17 | lcd.cls(); |
| 20172573073 | 0:304aaa70b2e8 | 18 | lcd.printf("MPU6050 OK"); |
| 20172573073 | 0:304aaa70b2e8 | 19 | wait(1); |
| 20172573073 | 0:304aaa70b2e8 | 20 | } else { |
| 20172573073 | 0:304aaa70b2e8 | 21 | lcd.cls(); |
| 20172573073 | 0:304aaa70b2e8 | 22 | lcd.printf("MPU6050 error ID=0x%x\r\n",mpu.getID()); |
| 20172573073 | 0:304aaa70b2e8 | 23 | while(1) { |
| 20172573073 | 0:304aaa70b2e8 | 24 | } |
| 20172573073 | 0:304aaa70b2e8 | 25 | } |
| 20172573073 | 0:304aaa70b2e8 | 26 | mpu.start(); |
| 20172573073 | 0:304aaa70b2e8 | 27 | tiempo_prev=timer.read_ms(); |
| 20172573073 | 0:304aaa70b2e8 | 28 | while(1) { |
| 20172573073 | 0:304aaa70b2e8 | 29 | |
| 20172573073 | 0:304aaa70b2e8 | 30 | mpu.readraw(&gx,&gy,&gz,&ax,&ay,&az); |
| 20172573073 | 0:304aaa70b2e8 | 31 | dt =(timer.read_ms() - tiempo_prev); |
| 20172573073 | 0:304aaa70b2e8 | 32 | tiempo_prev=timer.read_ms(); |
| 20172573073 | 0:304aaa70b2e8 | 33 | |
| 20172573073 | 0:304aaa70b2e8 | 34 | |
| 20172573073 | 0:304aaa70b2e8 | 35 | giro1x=(gx/131)*dt/1000.0+giro2x; |
| 20172573073 | 0:304aaa70b2e8 | 36 | giro1z=(gz/131)*dt/1000.0+giro2z; |
| 20172573073 | 0:304aaa70b2e8 | 37 | giro1y=(gy/131)*dt/1000.0+giro2y; |
| 20172573073 | 0:304aaa70b2e8 | 38 | giro2x=giro1x; |
| 20172573073 | 0:304aaa70b2e8 | 39 | giro2z=giro1z; |
| 20172573073 | 0:304aaa70b2e8 | 40 | giro2y=giro1y; |
| 20172573073 | 0:304aaa70b2e8 | 41 | lcd.cls(); |
| 20172573073 | 0:304aaa70b2e8 | 42 | lcd.printf("z: %f",giro1z); |
| 20172573073 | 0:304aaa70b2e8 | 43 | wait(1); |
| 20172573073 | 0:304aaa70b2e8 | 44 | lcd.cls(); |
| 20172573073 | 0:304aaa70b2e8 | 45 | lcd.printf("x: %f",giro1x); |
| 20172573073 | 0:304aaa70b2e8 | 46 | wait(1); |
| 20172573073 | 0:304aaa70b2e8 | 47 | lcd.cls(); |
| 20172573073 | 0:304aaa70b2e8 | 48 | lcd.printf("y: %f ",giro1y); |
| 20172573073 | 0:304aaa70b2e8 | 49 | wait(1); |
| 20172573073 | 0:304aaa70b2e8 | 50 | //pc.printf("Der: %5.1f ,Izq: %5.1f ",tDer,tIzq); |
| 20172573073 | 0:304aaa70b2e8 | 51 | |
| 20172573073 | 0:304aaa70b2e8 | 52 | } |
| 20172573073 | 0:304aaa70b2e8 | 53 | } |
| 20172573073 | 0:304aaa70b2e8 | 54 | |
| 20172573073 | 0:304aaa70b2e8 | 55 | ////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 20172573073 | 0:304aaa70b2e8 | 56 | |
| 20172573073 | 0:304aaa70b2e8 | 57 |