久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 16480|回復: 11
收起左側

arduino ps2遙控小車基于無線模塊

  [復制鏈接]
ID:305173 發表于 2018-4-27 12:15 | 顯示全部樓層 |閱讀模式
基于無線模塊的遙控控制小車
0.jpg 0.jpg

  
手柄按鍵
  
發送字符
接收十六進制代碼
小車動作
  
按鍵上或左搖桿上
  
a
0x61
前進
  
按鍵下或左搖桿下
  
b
0x62
后退
  
按鍵左或左搖桿左
  
c
0x63
左轉
  
按鍵右或左搖桿右
  
d
0x64
右轉
  
  



  
紅圓圈
  
e
0x65
左原地轉圈
  
粉方塊
  
f
0x66
右原地轉圈
  
綠三角
  
g
0x67
劃弧度
  
  



  
1或右1
  
h
0x68
左平移
  
2或右2
  
i
0x69
右平移
  
  



  
右搖桿上
  
g
0x6a
45度左前
  
右搖桿下
  
k
0x6b
45度右后
  
右搖桿左
  
l
0x6c
45度右前
  
右搖桿右
  
m
0x6d
45度左后
  
  



  
標志位
  
n
0x6e
停止

arduino源程序如下:
  1. #include <PS2X_lib.h>  //for v1.6

  2. PS2X ps2x; // create PS2 Controller Class

  3. //right now, the library does NOT support hot pluggable controllers, meaning
  4. //you must always either restart your Arduino after you conect the controller,
  5. //or call config_gamepad(pins) again after connecting the controller.
  6. //不支持熱插拔,連線后需要重新啟動Arduino板

  7. int PS_LX;//PS2手柄左搖桿X軸數據
  8. int PS_LY;//PS2手柄左搖桿Y軸數據
  9. int PS_RX;//PS2手柄右搖桿X軸數據
  10. int PS_RY;//PS2手柄右搖桿Y軸數據

  11. int error = 0;         //連接正確與否的判斷標志
  12. byte type = 0;         //ps2x.readType()轉換判別標志     
  13. byte vibrate = 0;
  14. int banduan=0;

  15. void setup(){
  16. Serial.begin(57600);

  17. //CHANGES for v1.6 HERE!!! **************PAY ATTENTION*************

  18. error = ps2x.config_gamepad(13,11,10,12, true, true);   //setup pins and settings:  GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error
  19.                                                          //檢查引腳是否有連接錯誤
  20.                                                          
  21. if(error == 0){
  22.    Serial.println("Found Controller, configured successful");
  23.    Serial.println("Try out all the buttons, X will vibrate the controller, faster as you press harder;");
  24.   Serial.println("holding L1 or R1 will print out the analog stick values.");
  25.   Serial.println("Go to [url]www*billporter*info[/url] for updates and to report bugs.");
  26. }  //0號錯誤的串口提示信息                        

  27.   else if(error == 1)
  28.    Serial.println("No controller found, check wiring, see readme.txt to enable debug. visit [url]www*billporter*info[/url] for troubleshooting tips");
  29.                   //1號錯誤的串口提示信息
  30.   else if(error == 2)
  31.    Serial.println("Controller found but not accepting commands. see readme.txt to enable debug. Visit [url]www*billporter*info[/url] for troubleshooting tips");
  32.                  //2號錯誤的串口提示信息
  33.   else if(error == 3)
  34.    Serial.println("Controller refusing to enter Pressures mode, may not support it. ");
  35.                  //3號錯誤的串口提示信息

  36.    //Serial.print(ps2x.Analog(1), HEX);

  37.    type = ps2x.readType();    //正確連接后串口提示的信息  
  38.      switch(type) {
  39.        case 0:
  40.         Serial.println("Unknown Controller type");
  41.        break;
  42.        case 1:
  43.         Serial.println("DualShock Controller Found");
  44.        break;
  45.        case 2:
  46.          Serial.println("GuitarHero Controller Found");
  47.        break;
  48.      }

  49. }

  50. void loop(){
  51.    /* You must Read Gamepad to get new values
  52.    Read GamePad and set vibration values
  53.    ps2x.read_gamepad(small motor on/off, larger motor strenght from 0-255)
  54.    if you don't enable the rumble, use ps2x.read_gamepad(); with no values
  55.    
  56.    you should call this at least once a second
  57.    */
  58. //用Read Gamepad函數讀取按鍵值


  59. if(error == 1) //skip loop if no controller found
  60.   return;
  61.   
  62.   
  63.   
  64.   /******************************************************
  65.    Guitar Hero Controller不是手柄選用的控制器
  66.   //Guitar Hero Controller
  67. if(type == 2)            
  68. {
  69.   ps2x.read_gamepad();          //read controller

  70.    if(ps2x.ButtonPressed(GREEN_FRET))
  71.      Serial.println("Green Fret Pressed");
  72.    if(ps2x.ButtonPressed(RED_FRET))
  73.      Serial.println("Red Fret Pressed");
  74.    if(ps2x.ButtonPressed(YELLOW_FRET))
  75.      Serial.println("Yellow Fret Pressed");
  76.    if(ps2x.ButtonPressed(BLUE_FRET))
  77.      Serial.println("Blue Fret Pressed");
  78.    if(ps2x.ButtonPressed(ORANGE_FRET))
  79.      Serial.println("Orange Fret Pressed");


  80.     if(ps2x.ButtonPressed(STAR_POWER))
  81.      Serial.println("Star Power Command");

  82.     if(ps2x.Button(UP_STRUM))          //will be TRUE as long as button is pressed
  83.      Serial.println("Up Strum");
  84.     if(ps2x.Button(DOWN_STRUM))
  85.      Serial.println("DOWN Strum");


  86.     if(ps2x.Button(PSB_START))                            //will be TRUE as long as button is pressed
  87.          Serial.println("Start is being held");
  88.     if(ps2x.Button(PSB_SELECT))                  
  89.          Serial.println("Select is being held");


  90.     if(ps2x.Button(ORANGE_FRET)) // print stick value IF TRUE
  91.     {
  92.         Serial.print("Wammy Bar Position:");
  93.         Serial.println(ps2x.Analog(WHAMMY_BAR), DEC);
  94.     }
  95. }
  96. **********************************************************************/
  97. else { //DualShock Controller手柄選用的控制器
  98.     ps2x.read_gamepad(false, vibrate);          //read controller and set large motor to spin at 'vibrate' speed
  99.    
  100.     if(ps2x.Button(PSB_START))                      //start選中 //will be TRUE as long as button is pressed
  101.       Serial.println("Start is being held");   
  102.     if(ps2x.Button(PSB_SELECT))                     //select選中
  103.       Serial.println("Select is being held");

  104.     PS_LX=ps2x.Analog(PSS_LX);           //把PS2手柄左搖桿X軸數據讀到變量PS_LX
  105.    PS_RX=ps2x.Analog(PSS_RX);           //把PS2手柄右搖桿X軸數據讀到變量PS_RX
  106.    PS_LY=ps2x.Analog(PSS_LY);           //把PS2手柄左搖桿Y軸數據讀到變量PS_LY
  107.    PS_RY=ps2x.Analog(PSS_RY);           //把PS2手柄右搖桿Y軸數據讀到變量PS_RY
  108.   if(PS_RX<5)                  //從左到右0~255,從上到下0~255      
  109.   { banduan=1;
  110.         Serial.print("l");  
  111.       }
  112.    if(PS_RX>250)
  113.    { banduan=1;
  114.         Serial.print("m");  
  115.       }
  116.     if(PS_RY<5)
  117.   { banduan=1;
  118.         Serial.print("j");  
  119.       }
  120.       if(PS_RY>250)
  121.   { banduan=1;
  122.         Serial.print("k");  
  123.       }




  124.     if(PS_LY<5||ps2x.Button(PSB_PAD_UP)) //上                   //will be TRUE as long as button is pressed
  125.     {  banduan=1;
  126.        Serial.print("a");               
  127.      }
  128.      
  129.      if(PS_LY>250||ps2x.Button(PSB_PAD_DOWN))//下
  130.       { banduan=1;
  131.        Serial.print("b");     
  132.       }
  133.      
  134.          if(PS_LX<5||ps2x.Button(PSB_PAD_LEFT))//左
  135.       { banduan=1;
  136.       Serial.print("c");   
  137.       }
  138.       
  139.      if(PS_LX>250||ps2x.Button(PSB_PAD_RIGHT))//右
  140.      { banduan=1;
  141.         Serial.print("d");  
  142.       }
  143.       
  144.      
  145.      if(ps2x.Button(PSB_RED))               //紅圓圈
  146.          { banduan=1;
  147.         Serial.print("e");  
  148.       }

  149.     if(ps2x.Button(PSB_PINK))             //粉方形
  150.        { banduan=1;
  151.         Serial.print("f");  
  152.       }
  153.   
  154.       
  155.       
  156.       
  157.       vibrate = ps2x.Analog(PSAB_BLUE);        //this will set the large motor vibrate speed based on how hard you press the blue (X) button   
  158.      if(ps2x.NewButtonState(PSB_BLUE))        //藍叉叉
  159.         Serial.print("XX");                                         

  160.     if (ps2x.Button(PSB_GREEN))              //綠三角   //will be TRUE if any button changes state (on to off, or off to on)
  161.      { banduan=1;
  162.         Serial.print("g");  
  163.       }


  164.   


  165.     if(ps2x.Button(PSB_L1) || ps2x.Button(PSB_R1)) //左1右1// print stick values if either is TRUE
  166.      { banduan=1;
  167.         Serial.print("h");  
  168.       }
  169.    if(ps2x.Button(PSB_L2) || ps2x.Button(PSB_R2)) //左2右2// print stick values if either is TRUE
  170.      { banduan=1;
  171.         Serial.print("i");  
  172.       }


  173.   if( banduan==0)
  174.       Serial.print("n");
  175.      else
  176.          banduan=0;
  177.      
  178. }
  179. delay(50);

  180. }
復制代碼


所有資料51hei提供下載:
遙控小車.rar (12.07 MB, 下載次數: 155)


0.jpg
回復

使用道具 舉報

ID:18156 發表于 2018-9-9 16:29 | 顯示全部樓層
看輪子應該是可以橫向運動的。
回復

使用道具 舉報

ID:32574 發表于 2018-10-17 14:13 | 顯示全部樓層
樓主厲害,輪子是叫什么名字?
回復

使用道具 舉報

ID:79544 發表于 2018-10-19 08:25 | 顯示全部樓層
樓主  接收是用的什么模塊?
回復

使用道具 舉報

ID:390585 發表于 2018-11-8 19:06 | 顯示全部樓層
redtxd 發表于 2018-10-17 14:13
樓主厲害,輪子是叫什么名字?

麥克納姆輪
回復

使用道具 舉報

6#
無效樓層,該帖已經被刪除
ID:460190 發表于 2019-2-15 21:00 | 顯示全部樓層
感謝分享
回復

使用道具 舉報

8#
無效樓層,該帖已經被刪除
ID:448145 發表于 2019-11-7 12:22 | 顯示全部樓層

感謝分享
回復

使用道具 舉報

ID:676603 發表于 2019-12-29 15:03 | 顯示全部樓層
很棒,一會研究源碼
回復

使用道具 舉報

ID:646222 發表于 2020-2-5 19:14 | 顯示全部樓層
感謝分享
回復

使用道具 舉報

ID:652804 發表于 2020-2-25 21:37 | 顯示全部樓層
感謝分享
回復

使用道具 舉報

ID:643484 發表于 2020-3-3 15:07 | 顯示全部樓層
感謝分享
回復

使用道具 舉報

14#
無效樓層,該帖已經被刪除
ID:171746 發表于 2021-1-26 16:57 | 顯示全部樓層
有ARDUINO 小車程序嗎?     哪個是51單片機的
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 色吊丝在线 | 久干网 | 男人天堂免费在线 | 综合久| 亚洲精品不卡 | av一级在线观看 | 国产区一区 | 欧美日韩中文字幕在线 | a级毛片免费高清视频 | 欧美一二三 | 久久天堂 | 亚洲三区视频 | 一级国产精品一级国产精品片 | 日韩一区中文字幕 | 在线视频第一页 | 黄色网址免费看 | 国产成人啪免费观看软件 | 国产亚洲精品久久情网 | 九九热精品在线 | 久久99视频这里只有精品 | 91欧美激情一区二区三区成人 | 激情视频中文字幕 | 久久亚洲天堂 | 黄网站涩免费蜜桃网站 | av一区二区在线观看 | 国产一区高清 | 久久久久久国 | 亚洲国产欧美一区 | 欧美日韩亚洲成人 | 老司机免费视频 | 九九伊人sl水蜜桃色推荐 | 精品欧美乱码久久久久久1区2区 | 国产精品久久久久久久久免费桃花 | 野狼在线社区2017入口 | 久久精品国产一区二区电影 | 色姑娘av| 伊人久久大香线 | 久久精品视频网站 | 国产精品美女www爽爽爽视频 | 亚洲精品一区二区三区中文字幕 | 夜夜爽99久久国产综合精品女不卡 |