Kiko Ishimoto / MyLib4

Dependents:   robocon2017mbed_contoroler_L2

Fork of MyLib by Kiko Ishimoto

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Nunchuck.h Source File

Nunchuck.h

00001 #ifndef NUNCHUCK_H
00002 #define NUNCHUCK_H
00003 
00004 
00005 #include "mbed.h"
00006 
00007 #define NUNCHUCK_ANALOGDATA 1  //1 : analog   0 : degital
00008 #define NUNCHUCK_DEADZONE 0    //analog stick's deadzone
00009 #define NUNCHUCK_ADDR    0xA4  // 0x52 << 1
00010 
00011 #define PI 3.14159265358979
00012 
00013 class Nunchuck : I2C
00014 {
00015     public:
00016 
00017         Nunchuck(PinName SDA, PinName SCL);
00018         int8_t analogx();
00019         int8_t analogy();
00020         double analograd();
00021         double analogdeg();
00022         double analogrange();
00023         int accx();
00024         int accy();
00025         int accz ();
00026         bool buttonc();
00027         bool buttonz();
00028         bool init();
00029         void getdata();
00030         void offset_(){
00031             offsetX = 0;
00032             offsetY = 0;
00033             
00034             for(int i = 0 ; i< 15;i++){
00035                 getdata();
00036                 wait(0.01);
00037             }
00038             offset = false;
00039             wait(0.2);
00040             //for(int i = 0;i<20;i++){
00041                 offsetX = (char)analogx();
00042                 offsetY = (char)analogy();
00043                 //2ごうき
00044                 //x:252
00045                 //y:9
00046                 //1ごうき
00047                 //x:0
00048                 //y:7
00049             //}
00050             //printf("\n%d , %d \n",offsetX,offsetY);
00051             offset = true;
00052             //offsetX= offsetX/20;
00053             //offsetY= offsetY/20;
00054         }
00055     private:
00056         Timer timer;
00057         bool flag;
00058         char data[6];
00059         int offsetX;
00060         int offsetY;
00061         bool offset;
00062 };
00063 
00064 #endif