Arduino PS2手柄小车代码
1、首先需要给Arduino的库文件中加入<PS2X_lib.h>这个库
https://github.com/madsci1016/Arduino-PS2X
2、接好小车左右转的电机
3、还需要将PS2手柄接收器和Arduino的板子接好线
4、烧录好下面的程序 开始感受快乐吧~~~
#include <PS2X_lib.h>
PS2X ps2x; // create PS2 Controller Class
int leftmotor1 = 2;
int leftmotor2 =3;
int rightmotor1 = 4 ;
int rightmotor2 = 5 ;
int EN1=6;
int EN2=9;
int error = 0;
byte type = 0;
byte vibrate = 0;
void setup(){
pinMode (leftmotor1, OUTPUT );
pinMode (leftmotor2, OUTPUT);
pinMode (rightmotor1, OUTPUT );
pinMode ( rightmotor2, OUTPUT );
pinMode (EN1, OUTPUT );
pinMode ( EN2, OUTPUT );
Serial.begin(57600);
error = ps2x.config_gamepad(13,