![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
acelerometro de auteco
Dependencies: MMA8451Q TextLCD mbed
Fork of Tarea8accelerometro by
Diff: main.cpp
- Revision:
- 9:07e404aea94e
- Parent:
- 8:a2b340994747
--- a/main.cpp Tue Dec 10 19:26:21 2013 +0000 +++ b/main.cpp Wed May 07 22:51:30 2014 +0000 @@ -4,40 +4,88 @@ #define MMA8451_I2C_ADDRESS (0x1d<<1) -TextLCD lcd(PTB10, PTB11, PTE2, PTE3, PTE4, PTE5); // rs, e, d4-d7 -float acx=0,acy=0,acz=0; - +TextLCD lcd(PTB8, PTB9, PTB10, PTB11, PTE2, PTE3); // rs, e, d4-d7 +float acx=0,acy=0,acz=0, filtro=0; +float faroin1, faroin2, faroout; int main(void) { MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS); PwmOut rled(LED_RED); PwmOut gled(LED_GREEN); PwmOut bled(LED_BLUE); + + PwmOut acx(PTD4); + PwmOut acy(PTA12); + PwmOut acz(PTA4); + + AnalogIn faroin1(PTB3); + AnalogIn faroin2(PTB2); + DigitalOut faroout(PTA13); + + Serial pc(USBTX, USBRX); // tx, rx + lcd.locate(0,0); + lcd.printf("Medicion"); + lcd.locate(0,1); lcd.printf("Acelerometro"); wait(2); lcd.locate(0,0); - lcd.printf("acx=0 acy=0"); + lcd.printf("x= y="); lcd.locate(0,1); - lcd.printf("acz=0 "); + lcd.printf("z= "); while (true) { + rled = 1.0 - abs(acc.getAccX()); - acx=1.0 - abs(acc.getAccX()); gled = 1.0 - abs(acc.getAccY()); - acy=1.0 - abs(acc.getAccY()); bled = 1.0 - abs(acc.getAccZ()); - acz=1.0 - abs(acc.getAccZ()); - lcd.locate(4,0); - lcd.printf(" "); - lcd.locate(4,0); - lcd.printf("%1.2f",acx); - lcd.locate(12,0); - lcd.printf(" "); - lcd.locate(12,0); - lcd.printf("%1.2f",acy); - lcd.locate(4,1); + if (faroin1 > 0.5 or faroin2 > 0.5) { + faroout = 1; + filtro=((acc.getAccX()+(2*filtro))/3); + if (acc.getAccX() > 0) { + acx=0.5 + (filtro*2); + acy=0.5 - (filtro*2); + } + else { + acx=0.5 + (filtro*2); + acy=0.5 - (filtro*2); + } + if (acx > 1 or acy > 1) { + acx=1; + acy=1; + } + else if (acx<0 or acy<0) { + acx=0; + acy=0; + } + } + else { + faroout = 0; + acx=0.5; + acy=0.5; + } + + + //acz=0.0 + (acc.getAccZ()); + + + lcd.locate(2,0); lcd.printf(" "); - lcd.locate(4,1); - lcd.printf("%1.2f",acz); - wait(0.2); + lcd.locate(2,0); +/* + lcd.printf("%2.2f",acx); + lcd.locate(11,0); + lcd.printf(" "); + lcd.locate(11,0); + lcd.printf("%2.2f",acy); + lcd.locate(2,1); + lcd.printf(" "); + lcd.locate(2,1); + lcd.printf("%2.2f",acz); +*/ + wait(0.2); + //pc.printf(("%f %f %f ,"),acc.getAccX(),acc.getAccY(),acc.getAccZ()); + pc.printf(("%f %f %f"),acx.read(),acy.read(),faroin1.read()); + //pc.printf(("%f %f ,"),acx.read(),acy.read()); + //faroin2.read() + wait(0.2); //287 o 289 fluke } }