Yasuaki Kobayashi / Mbed 2 deprecated Android コントローラー

Dependencies:   MMA8451Q TextLCD mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include <math.h>
00003 #include "MMA8451Q.h"
00004 #include "TextLCD.h"
00005 #define MMA8451_I2C_ADDRESS (0x1d<<1)
00006 
00007 
00008     //  LCD (RS, E, D4, D5, D6, D7)
00009     TextLCD lcd(PTA13, PTD5, PTA4, PTA5, PTC8, PTC9); // LCD Shield for Arduino (DFR00009)
00010     //AnalogIn button(PTB0);  // board button
00011     PwmOut backlight(PTD0);
00012     Serial serial(USBTX,USBRX);
00013     DigitalIn BK(PTE5);
00014     DigitalIn ACC(PTE4);
00015     DigitalIn LIGHT(PTE3);
00016     DigitalIn WR(PTE2);
00017     DigitalIn WL(PTB11);
00018     DigitalIn WIPE(PTB10);
00019     int BK1,ACC1,LIGHT1,WR1,WL1,WIPE1;
00020     DigitalOut led(LED_RED);
00021     int main() {
00022     backlight = 1;  // ON: 1, OFF: 0
00023     MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
00024     //if(!BK ){
00025     //BK1 = 1;}
00026     //else {BK1=0;}
00027     
00028     PwmOut rled(LED_RED);
00029     PwmOut gled(LED_GREEN);
00030     PwmOut bled(LED_BLUE);
00031     double hnd,hnd1;
00032     while (1) {
00033         if(!BK ){BK1=1;}
00034         else {BK1=0;}
00035         if(!ACC ){ACC1=1;}
00036         else {ACC1=0;}
00037         if(!LIGHT ){LIGHT1=1;}
00038         else {LIGHT1=0;}
00039         if(!WR ){WR1=1;}
00040         else {WR1=0;}
00041         if(!WL ){WL1=1;}
00042         else {WL1=0;}
00043         if(!WIPE ){WIPE1=1;}
00044         else {WIPE1=0;}
00045         rled = 1.0 - abs(acc.getAccX());
00046         gled = 1.0 - abs(acc.getAccY());
00047         bled = 1.0 - abs(acc.getAccZ());
00048         lcd.locate(0,0);
00049         lcd.printf("X=%1.2f", acc.getAccX());  // button value
00050         lcd.printf(" ");
00051         lcd.locate(8,0);
00052         lcd.printf("Y=%1.2f", acc.getAccY());  // button value
00053         lcd.printf(" ");
00054         lcd.locate(0,1);
00055         lcd.printf("Z=%1.2f", acc.getAccZ());  // button value
00056         if( acc.getAccX() > 0.99)
00057         {hnd1=0.99;}
00058         else if(acc.getAccX() < -0.99)
00059         {hnd1=-0.99;}
00060         else{
00061         hnd1 = acc.getAccX();
00062         }
00063         if( acc.getAccY() < -0.1 )
00064         {
00065         if( acc.getAccX() < -0.2 )
00066         {hnd1=-0.99;}
00067         {}
00068         }
00069         {}
00070         if( acc.getAccY() < -0.1 )
00071         {
00072         if( acc.getAccX() > 0.2 )
00073         {hnd1=0.99;}
00074         {}
00075         }
00076         {}
00077         
00078         
00079         hnd = asin(hnd1)/3.14*180;
00080         lcd.printf(" ");
00081         lcd.locate(8,1);
00082         lcd.printf("H=%3.1f", hnd);   // ハンドル
00083         serial.printf("{\"x\":%5.2f,\"y\":%5.2f,\"z\":%5.2f,\"hnd\":%3.1f,\"BK1\":%d,\"ACC1\":%d,\"LIGHT1\":%d,\"WR1\":%d,\"WL1\":%d,\"WIPE1\":%d,}\r\n",acc.getAccX(), acc.getAccY(), acc.getAccZ(),hnd,BK1,ACC1,LIGHT1,WR1,WL1,WIPE1);
00084         wait(0.3);
00085     }
00086 }