#define CUSTOM_SETTINGS
#define INCLUDE_GAMEPAD_MODULE
#include <evive.h>
#include <Dabble.h>

unsigned int variable =0;
#define wait 100

void setup() 
   {
      // put your setup code here, to run once:
      Serial.begin(9600);
      Dabble.begin(115200);  

    } 

void loop() 
    {
       // put your main code here, to run repeatedly:

        Dabble.processInput();             //this function is used to refresh data obtained from smartphone.Hence calling this function is mandatory in order to get data properly from your mobile.
        variable =0;
        int a = GamePad.getAngle();
        int b = GamePad.getRadius();

        if (GamePad.isUpPressed())
           {
               variable = 1;
               Serial.print(variable);
               Serial.print(".");
               delay(wait);
           }
        if (GamePad.isDownPressed())
            {
               variable = 2;
               Serial.print(variable);
               Serial.print(".");
               delay(wait);
            }
        if (GamePad.isSquarePressed())
            { 
               variable = 3;
               Serial.print(variable);
               Serial.print(".");
               delay(wait);
            }

        if (GamePad.isCirclePressed())
            {
               variable = 4;
               Serial.print(variable);
               Serial.print(".");
               delay(wait);
            }
             if (GamePad.isLeftPressed())
           {
              variable = 3;
              Serial.print(variable);
              Serial.print(".");
              delay(wait);
           }

        if (GamePad.isRightPressed())
           {
              variable = 4;
              Serial.print(variable);
              Serial.print(".");
              delay(wait);
           }
            if (GamePad.isCrossPressed())
           {
              variable = 5;
              Serial.print(variable);
              Serial.print(".");
              delay(wait);
           }

        if (GamePad.isTrianglePressed())
           {
              variable = 1;
              Serial.print(variable);
              Serial.print(".");
              delay(wait);
           }

             if((a<45 || a>315)&& b>1)
            {
                variable = 4;
                Serial.print(variable);
                Serial.print(".");
                delay(wait);
            }
         if((a>45 && a<135) && b>1)
              {
                 variable = 1;
                 Serial.print(variable);
                 Serial.print(".");
                 delay(wait);
              }
          if((a>135 && a<225)&& b>1)
               {
                 variable = 3;
                 Serial.print(variable);
                 Serial.print(".");
                 delay(wait);
               }
           if((a>225 && a<315)&& b>1)
               {
                 variable = 2;
                 Serial.print(variable);
                 Serial.print(".");
                 delay(wait);
               }
         else
             {
                 Serial.print(variable);
                 Serial.print(".");
             }

}
