首页 > 编程知识 正文

ps2手柄按键示意图,ps2游戏手柄使用

时间:2023-05-03 22:47:34 阅读:57725 作者:1435

arduino的PS2方向盘热情鸭测试: #include PS2X_lib.h//电机端子#define PWMA 12 //A电机转速#defineDira134#defineDira235///a define DIRB2 36 //B电机方向#define PWMC 9 //C电机转速# defined IRC 143 # defined IRC 242///c电机方向#define PWMD 5 //D电机转速# c电机转速define DIRD2 27 //D电机方向//PS2热情鸭器# define PS2 _ dat 52//14 #”define PS2 _ cmd 51//15 # define PS2 _ sel 55292; 数字写入(dir a2,HIGH ); 模拟写入(PWM,PWM ); }while(0) #define MOTORA_STOP(x ) x ) do )数字写入(dira 1,LOW ); 数字写入(dir a2,LOW ); 模拟写入(pwma,0 ); }while(0) # define motora _ back off (PWM ) do ) digitalwrite(dira1,HIGH ); 数字写入(dir a2,LOW ); 模拟写入(PWM,PWM ); }while(0) #definemotorb_forward ) PWM ) do )数字写入(dir B1,LOW ); 数字写入(dir B2,HIGH ); 模拟写入(pwm,pwm ); }while(0) #define MOTORB_STOP(x ) x ) do )数字写入(dir B1,LOW ); 数字写入(dir B2,LOW ); 模拟写入(pwmb,0 ); }while(0) # definemotorb _ back off (PWM ) do ) digitalwrite(dirB1,HIGH ); 数字写入(dir B2,LOW ); 模拟写入(pwm,pwm ); }while(0) # define motorc _ forward (PWM ) do ) digitalwrite(dirC1,LOW ); 数字写入(dir C2,HIGH ); 模拟写入(PWM,PWM ); }while(0) #define MOTORC_STOP(x ) x ) do )数字写入(dir C1,LOW ); 数字写入(dir C2,LOW ); 模拟写入(pwmc,0 ); }while(0) # define motorc _ back off (PWM ) do ) digitalwrite(dirC1,HIGH ); 数字写入(dir C2,LOW ); 模拟写入(PWM,PWM ); }while(0) # define motord _ forward (PWM ) do ) digitalwrite(dirD1,LOW ); 数字写入(dir D2,HIGH ); 模拟写入(pwm,pwm ); }while(0) #define MOTORD_STOP(x ) x ) do )数字写入(dir D1,LOW ); 数字写入(dir D2,LOW ); 模拟写入(pwmd,0 ); }while(0) # define motord _ back off (PWM ) do ) digitalwrite(dirD1,HIGH ); 数字写入(dir D2,LOW ); 模拟写入(pwm,pwm ); }while(0) #define SERIAL Serial#define MAX美丽荷包蛋200 ) definemin美丽荷包蛋100int Motor美丽荷包蛋=130; //热情鸭马达运动宏定义//a---- b//||/|||/--- dvoid高级({ motora _ forward }/mor ward motorc_Forward(motor美丽的煎蛋); motord _ forward (马达美丽的荷包蛋); (/a---b/|| /c---dvoid back ({ motora _ back off ) motor美丽的荷包蛋}; 移动_后退关闭(motor优美的煎蛋); MOTORC_BACKOFF(Motor优美的煎蛋);MOTORD_BACKOFF(Motor优美的煎蛋);}// =A-----B↑ // | ↖ |// | ↖ |// ↑C-----D=void LEFT_1(){ MOTORA_FORWARD(Motor优美的煎蛋);MOTORB_STOP(Motor优美的煎蛋); MOTORC_STOP(Motor优美的煎蛋);MOTORD_FORWARD(Motor优美的煎蛋);}// ↓A-----B↑ // | ← |// | ← |// ↑C-----D↓void LEFT_2(){ MOTORA_BACKOFF(Motor优美的煎蛋);MOTORB_FORWARD(Motor优美的煎蛋); MOTORC_FORWARD(Motor优美的煎蛋);MOTORD_BACKOFF(Motor优美的煎蛋);}// ↓A-----B= // | ↙ |// | ↙ |// =C-----D↓void LEFT_3(){ MOTORA_BACKOFF(Motor优美的煎蛋);MOTORB_STOP(Motor优美的煎蛋); MOTORC_STOP(Motor优美的煎蛋);MOTORD_BACKOFF(Motor优美的煎蛋);}// ↑A-----B= // | ↗ |// | ↗ |// =C-----D↑void RIGHT_1(){ MOTORA_FORWARD(Motor优美的煎蛋);MOTORB_STOP(Motor优美的煎蛋); MOTORC_STOP(Motor优美的煎蛋);MOTORD_FORWARD(Motor优美的煎蛋);}// ↑A-----B↓ // | → |// | → |// ↓C-----D↑void RIGHT_2(){ MOTORA_FORWARD(Motor优美的煎蛋);MOTORB_BACKOFF(Motor优美的煎蛋); MOTORC_BACKOFF(Motor优美的煎蛋);MOTORD_FORWARD(Motor优美的煎蛋);}// =A-----B↓ // | ↘ |// | ↘ |// ↓C-----D=void RIGHT_3(){ MOTORA_STOP(Motor优美的煎蛋);MOTORB_BACKOFF(Motor优美的煎蛋); MOTORC_BACKOFF(Motor优美的煎蛋);MOTORD_STOP(Motor优美的煎蛋);}// =A-----B= // | = |// | = |// =C-----D=void STOP(){ MOTORA_STOP(Motor优美的煎蛋);MOTORB_STOP(Motor优美的煎蛋); MOTORC_STOP(Motor优美的煎蛋);MOTORD_STOP(Motor优美的煎蛋);}void UART_Control(){ char Uart_Date=0; if(SERIAL.available()) { Uart_Date = SERIAL.read(); } switch(Uart_Date) { case 'A': ADVANCE(); break; case 'B': RIGHT_1(); break; case 'C': RIGHT_2(); break; case 'D': RIGHT_3(); break; case 'E': BACK(); break; case 'F': LEFT_3(); break; case 'G': LEFT_2(); break; case 'H': LEFT_1(); break; case 'Z': STOP(); break; case 'L': Motor优美的煎蛋 = 240; break; case 'M': Motor优美的煎蛋 = 130; break; }}void IO_init(){ pinMode(PWMA, OUTPUT); pinMode(DIRA1, OUTPUT); pinMode(DIRA2, OUTPUT); pinMode(PWMB, OUTPUT); pinMode(DIRB1, OUTPUT); pinMode(DIRB2, OUTPUT); pinMode(PWMC, OUTPUT); pinMode(DIRC1, OUTPUT); pinMode(DIRC2, OUTPUT); pinMode(PWMD, OUTPUT); pinMode(DIRD1, OUTPUT); pinMode(DIRD2, OUTPUT); STOP();}void setup(){ int error,type; Serial.begin(9600); delay(300) ;//added delay to give wireless ps2 module some time to startup, before configuring it //CHANGES for v1.6 HERE!!! **************PAY ATTENTION************* ps2x.config_gamepad(PS2_CLK, PS2_CMD, PS2_SEL, PS2_DAT, false, false); type = ps2x.readType(); switch (type) { case 0: Serial.print("Unknown Controller type found "); break; case 1: Serial.print("DualShock Controller found "); break; case 2: Serial.print("GuitarHero Controller found "); break; case 3: Serial.print("Wireless Sony DualShock Controller found "); break; } IO_init();}void loop() { byte vibrate = 0; UART_Control();//串口接收处理 ps2x.read_gamepad(false, vibrate); //read controller and set large motor to spin at 'vibrate' speed//start 开始运行,电机zxddr为120; if (ps2x.Button(PSB_START)) { Serial.println("Start"); Motor优美的煎蛋 = 90; ADVANCE(); }// 电机正转; if (ps2x.Button(PSB_PAD_UP)) { Serial.println("Up held this hard: "); Motor优美的煎蛋 = 120; ADVANCE(); }// 电机反转; if (ps2x.Button(PSB_PAD_DOWN)) { Serial.println("Down held this hard: "); Motor优美的煎蛋 = 120; BACK(); }//左转; if (ps2x.Button(PSB_PAD_LEFT)) { Serial.println("turn left "); Motor优美的煎蛋 = 120;//200 LEFT_1(); }//右转; if (ps2x.Button(PSB_PAD_RIGHT)) { Serial.println("turn right"); Motor优美的煎蛋 = 120;//200 RIGHT_1(); }// Stop if (ps2x.Button(PSB_SELECT)) { Serial.println("stop"); STOP(); }// 左平移 if (ps2x.Button(PSB_PINK)) { Serial.println("motor_pmove_left"); LEFT_2(); }// 右平移 if (ps2x.Button(PSB_RED)) { Serial.println("motor_pmove_right"); RIGHT_2(); } vibrate = ps2x.Analog(PSAB_CROSS); //this will set the large motor vibrate speed based on how hard you press the blue (X) button if (ps2x.pydqb()) { //will be TRUE if any button changes state (on to off, or off to on) if(ps2x.Button(PSB_L3)) Serial.println("L3 pressed"); if(ps2x.Button(PSB_R3)) Serial.println("R3 pressed"); if(ps2x.Button(PSB_L2)) Serial.println("L2 pressed"); if(ps2x.Button(PSB_R2)) Serial.println("R2 pressed"); if(ps2x.Button(PSB_TRIANGLE)) Serial.println("Triangle pressed"); } // 摇杆测试 int LX,LY,RX,RY; LY=ps2x.Analog(PSS_LY); //中间值127 LX=ps2x.Analog(PSS_LX); //中间值128 RY=ps2x.Analog(PSS_RY); //中间值127 RX=ps2x.Analog(PSS_RX); //中间值128 Serial.print("Stick Values:"); Serial.print(LY); Serial.print(LX); Serial.print(RY); Serial.println(RX); delay(20);}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。