Guest User

Untitled

a guest
Jul 30th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Joystick.h>//includes the library we download
  2.  
  3. Joystick_ Joystick; //creates the joystick
  4. int VRxAxis_ = 0;     //introducing the variables
  5. int VRyAxis_ = 0;
  6. int XAxis_ = 0;
  7. int YAxis_ = 0;
  8.  
  9.  
  10.  
  11. const bool initAutoSendState = true;
  12.  
  13. void setup()
  14. {
  15.   pinMode(9, INPUT_PULLUP);//sets up all our buttons
  16.   pinMode(4, INPUT_PULLUP);
  17.   pinMode(10, INPUT_PULLUP);
  18.   pinMode(14, INPUT_PULLUP);
  19.   pinMode(15, INPUT_PULLUP);
  20.   pinMode(2, INPUT_PULLUP);
  21.          Joystick.begin();//starts joystick
  22.            Serial.begin(9600);
  23. }
  24.  
  25.  
  26.  
  27.  
  28.   void loop(){
  29.    
  30.  
  31.     VRxAxis_ = analogRead(A2);//our variable is equal to the input from analog pin 2
  32.     VRxAxis_ = map(VRxAxis_,0,1023,255,0);//map the variable
  33.      Joystick.setRxAxis(VRxAxis_);//links the joystick's right xaxis to our input variable
  34.  
  35.     VRyAxis_ = analogRead(A3);
  36.     VRyAxis_ = map(VRyAxis_,1023,0,255,0);
  37.      Joystick.setRxAxis(VRxAxis_);
  38.  
  39.     XAxis_ = analogRead(A1);
  40.     XAxis_ = map(XAxis_,0,1023,255,0);
  41.      Joystick.setRxAxis(XAxis_);
  42.  
  43.     YAxis_ = analogRead(A0);
  44.     YAxis_ = map(YAxis_,0,1023,255,0);
  45.      Joystick.setRxAxis(YAxis_);
  46.  
  47.      if (digitalRead(9)== LOW)//if the button connected to pin 9 is pressed
  48.      {Joystick.pressButton(0);}//button 0 is pressed
  49.      else
  50.      {Joystick.releaseButton(0);}//if the button connected to pin 9 is not pressed release button 0
  51.  
  52.      if (digitalRead(4)== LOW)
  53.      {Joystick.pressButton(1);}
  54.      else
  55.      {Joystick.releaseButton(1);}
  56.  
  57.      if (digitalRead(10)== LOW)
  58.      {Joystick.pressButton(2);}
  59.      else
  60.      {Joystick.releaseButton(2);}
  61.  
  62.      if (digitalRead(14)== LOW)
  63.      {Joystick.pressButton(3);}
  64.      else
  65.      {Joystick.releaseButton(3);}
  66.  
  67.      if (digitalRead(15)== LOW)
  68.      {Joystick.pressButton(4);}
  69.      else
  70.      {Joystick.releaseButton(4);}
  71.  
  72.   Serial.println(" A0:");
  73.   Serial.print(analogRead(A0));
  74.   Serial.print(" A1:");
  75.   Serial.print(analogRead(A1));
  76.   Serial.print(" A1:");
  77.   Serial.print(analogRead(A1));
  78.   Serial.print(" A3:");
  79.   Serial.print(analogRead(A3));
  80.   Serial.print(" D2:");
  81.   Serial.print(digitalRead(2));
  82.   Serial.print(" D4:");
  83.   Serial.print(digitalRead(4));
  84.   Serial.print(" D9:");
  85.   Serial.print(digitalRead(9));
  86.   Serial.print(" D10:");
  87.   Serial.print(digitalRead(10));
  88.   Serial.print(" D14:");
  89.   Serial.print(digitalRead(14));
  90.   Serial.print(" D15:");
  91.   Serial.print(digitalRead(15));
  92.  
  93.  
  94.  
  95.      delay(10);
  96.   }
Add Comment
Please, Sign In to add comment