Advertisement
KRITSADA

IPST-SE Motor Control With Bluestick and Joy PSX

Sep 8th, 2016
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. #include <ipst.h> // IPST-SE Board
  2. #include <PS2X_lib.h>
  3. #define PS2_DAT  26  
  4. #define PS2_CMD  27
  5. #define PS2_SEL  28
  6. #define PS2_CLK  29
  7. int error;
  8. int x;
  9. PS2X psx;
  10. void setup(){
  11.   setTextSize(2);glcdMode(1);
  12.   glcd(0,0,"OK->Bluetooth");
  13.   glcd(1,0,"SW1->JOY PSX");
  14.   while(1){
  15.     if(sw1()){joy();}
  16.     if(sw_OK()){blue();}
  17.   }
  18. }
  19. void loop(){}
  20. void blue(){
  21.   glcdClear();
  22.   setTextSize(3);glcdMode(1);
  23.   setTextColor(GLCD_BLUE);
  24.   glcd(1,0,"Bluetooth");
  25.   pinMode(2,INPUT_PULLUP);
  26.   while(!sw1()){
  27.     if (uart1_available()) {
  28.        x=uart1_getkey();
  29.       if(x==0x38){fd(100);}
  30.       else if(x==0x32){bk(100);}
  31.       else if(x==0x34){sl(100);}
  32.       else if(x==0x36){sr(100);}
  33.       else {ao();}
  34.     }
  35.   }
  36. }
  37. void joy(){
  38.   glcdClear();
  39.   setTextSize(3);glcdMode(1);
  40.   setTextColor(GLCD_YELLOW);
  41.   glcd(1,0,"JOY PSX");
  42.    while(1){
  43.     if (!psx.config_gamepad(PS2_CLK, PS2_CMD, PS2_SEL, PS2_DAT, false, false)){
  44.       setTextColor(GLCD_RED);setTextSize(2);
  45.       glcd(3,0,"Connected ");
  46.       break;
  47.     }
  48.    }
  49.    while(!sw_OK()){
  50.    psx.read_gamepad(0,0);    // Read PSX
  51.     if(psx.Button(PSB_PAD_UP)||psx.Button(PSB_TRIANGLE)){fd(100);}  
  52.     else if(psx.Button(PSB_PAD_DOWN)||psx.Button(PSB_CROSS)){bk(100);}
  53.     else if(psx.Button(PSB_PAD_LEFT)||psx.Button(PSB_SQUARE)){sl(100);}
  54.     else if(psx.Button(PSB_PAD_RIGHT)||psx.Button(PSB_CIRCLE)){sr(100);}
  55.     else{ao();}
  56.   }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement