mylib

Dependents:   robocon2017mbed_control_R

Fork of MyLib by gaku takasawa

Nunchuck/Nunchuck.h

Committer:
kikoaac
Date:
2017-10-27
Revision:
13:b375df74762c
Parent:
12:9b31ab2a6ce2

File content as of revision 13:b375df74762c:

#ifndef NUNCHUCK_H
#define NUNCHUCK_H


#include "mbed.h"

#define NUNCHUCK_ANALOGDATA 1  //1 : analog   0 : degital
#define NUNCHUCK_DEADZONE 0    //analog stick's deadzone
#define NUNCHUCK_ADDR    0xA4  // 0x52 << 1

#define PI 3.14159265358979

class Nunchuck : I2C
{
    public:

        Nunchuck(PinName SDA, PinName SCL);
        int8_t analogx();
        int8_t analogy();
        double analograd();
        double analogdeg();
        double analogrange();
        int accx();
        int accy();
        int accz ();
        bool buttonc();
        bool buttonz();
        bool init();
        void offset_(){
            offsetX = 0;
            offsetY = 0;
            offset = false;
            for(int i = 0 ; i< 10;i++){
                getdata();
                wait(0.01);
            }
            wait(0.2);
            
            //for(int i = 0;i<20;i++){
                offsetX = (char)analogx();
                offsetY = (char)analogy();
            //}
            offset = true;
            //offsetX= offsetX/20;
            //offsetY= offsetY/20;
        }
        void getdata();
    private:
        Timer timer;
        bool flag;
        char data[6];
        int offsetX;
        int offsetY;
        bool offset;
};

#endif