5.5 arduino连接ps2转接板

PS2转接板简介:

这是一个ps2转接板,目的是把ps2转成杜邦插口,期间没有任何其它电路。

材料清单:

库文件:

ps2x_lib

线路图:

.5

如果使用米思齐,接线图如下:

.5

测试代码:

#define PS2_DAT 12
#define PS2_CMD 11
#define PS2_CS 10
#define PS2_CLK 13
#include "PS2X_lib.h"

volatile int flag_rocker;
volatile int flag_motor1;

PS2X ps2x;

void setup(){
  flag_rocker = 0;
  flag_motor1 = 0;
  Serial.begin(9600);
  ps2x.config_gamepad(PS2_CLK, PS2_CMD, PS2_CS, PS2_DAT, true, true);

}

void loop(){
  if (flag_motor1 == 0) {
    ps2x.read_gamepad(false,ps2x.Analog(PSAB_CROSS));

  } else {
    ps2x.read_gamepad(true,0);

  }
  if (ps2x.ButtonPressed(PSB_START)) {
    Serial.println("Start pressed");

  }
  if (ps2x.ButtonPressed(PSB_SELECT)) {
    Serial.println("Select pressed");

  }

  if (ps2x.ButtonPressed(PSB_PAD_UP)) {
    Serial.print("Up held this hard:");
    Serial.println(ps2x.Analog(PSAB_PAD_UP));

  }
  if (ps2x.ButtonPressed(PSB_PAD_RIGHT)) {
    Serial.print("Right held this hard:");
    Serial.println(ps2x.Analog(PSAB_PAD_RIGHT));

  }
  if (ps2x.ButtonPressed(PSB_PAD_LEFT)) {
    Serial.print("Left held this hard:");
    Serial.println(ps2x.Analog(PSAB_PAD_LEFT));

  }
  if (ps2x.ButtonPressed(PSB_PAD_DOWN)) {
    Serial.print("Down held this hard:");
    Serial.println(ps2x.Analog(PSAB_PAD_DOWN));
    flag_motor1 = 1;

  } else if (ps2x.ButtonReleased(PSB_PAD_DOWN) == 1) {
    flag_motor1 = 0;
  }

  if (ps2x.ButtonPressed(PSB_CROSS)) {
    Serial.println("Cross");

  }
  if (ps2x.ButtonPressed(PSB_CIRCLE)) {
    Serial.println("Circle");

  }
  if (ps2x.ButtonPressed(PSB_SQUARE)) {
    Serial.println("Square");

  }
  if (ps2x.ButtonPressed(PSB_TRIANGLE)) {
    Serial.println("Triangle");

  }
  if (ps2x.ButtonPressed(PSB_L1)) {
    Serial.println("L1");
    flag_rocker = 1;

  } else if (ps2x.ButtonReleased(PSB_L1) == 1) {
    flag_rocker = 0;
  }
  if (ps2x.ButtonPressed(PSB_R1)) {
    Serial.println("R1");
    flag_rocker = 1;

  } else if (ps2x.ButtonReleased(PSB_R1) == 1) {
    flag_rocker = 0;
  }
  if (ps2x.ButtonPressed(PSB_L2)) {
    Serial.println("L2");

  }
  if (ps2x.ButtonPressed(PSB_R2)) {
    Serial.println("R2");

  }
  if (ps2x.ButtonPressed(PSB_L3)) {
    Serial.println("L3");

  }
  if (ps2x.ButtonPressed(PSB_R3)) {
    Serial.println("R3");

  }

  if (flag_rocker == 1) {
    Serial.print("Stick Values:");
    Serial.print(ps2x.Analog(PSS_LX));
    Serial.print(",");
    Serial.print(ps2x.Analog(PSS_LY));
    Serial.print(",");
    Serial.print(ps2x.Analog(PSS_RX));
    Serial.print(",");
    Serial.println(ps2x.Analog(PSS_RY));

  }
  delay(30);

}

米思齐测试例程:

https://www.haibucuo.com/download/mixly%e8%bd%bb%e6%9d%be%e5%85%a5%e9%97%a8-%e6%8b%93%e5%b1%95%ef%bc%9aps2%e6%89%8b%e6%9f%84%e6%8e%a7%e5%88%b6%e4%be%8b%e7%a8%8b

测试效果:

.5

>>问题反馈请点击这里

更新记录:

2021.10.15创建

联系我们

联系我们

微信:13823392571

在线咨询:点击这里给我发消息

工作时间:周一至周五,9:30-18:30,节假日休息

微信客服
微信客服
分享本页
返回顶部