Kiko Ishimoto / MyLib2

Dependents:   robocon2017mbed_control_R

Fork of MyLib by gaku takasawa

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 offset_(){
00030             offsetX = 0;
00031             offsetY = 0;
00032             offset = false;
00033             for(int i = 0 ; i< 10;i++){
00034                 getdata();
00035                 wait(0.01);
00036             }
00037             wait(0.2);
00038             
00039             //for(int i = 0;i<20;i++){
00040                 offsetX = (char)analogx();
00041                 offsetY = (char)analogy();
00042             //}
00043             offset = true;
00044             //offsetX= offsetX/20;
00045             //offsetY= offsetY/20;
00046         }
00047         void getdata();
00048     private:
00049         Timer timer;
00050         bool flag;
00051         char data[6];
00052         int offsetX;
00053         int offsetY;
00054         bool offset;
00055 };
00056 
00057 #endif