站架 Android手若何用Arduino芽ES@竹站架|PChome Online 人新台
2023-04-21 06:52:55| 人30| 回0 | 上一篇 | 下一篇

站架 Android手若何用Arduino芽ES

0 收藏 0 0 站台



ESP32 控制 TB6612FNG 直流制板 看篇

 

使用Android手若何用Arduino芽ESP32制蜘蛛械人
需要利用源
若是利用源,流被抽走
ESP32晶片流不足法正常作


材料:
18650池*2
ESP32*1
TB6612FNG*1
蜘蛛器人*2


 

1.jpg

2.jpg




AUDINO 程式

  1. // Include necessary libraries
  2. #include <BLEDevice.h>
  3. #include <BLEServer.h>
  4. #include <BLEUtils.h>
  5.  
  6. // 界 UUIDs (注意要App Inventor容)
  7. #define SERVICE_UUID            "C6FBDD3C-7123-4C9E-86AB-005F1A7EDA01"
  8. #define CHARACTERISTIC_UUID_RX  "B88E098B-E464-4B54-B827-79EB2B150A9F"
  9. #define CHARACTERISTIC_UUID_TX  "D769FACF-A4DA-47BA-9253-65359EE480FB"
  10.  
  11. String BLE_Code;
  12. BLECharacteristic *pCharacteristic;
  13. bool deviceCOnnected= false;
  14.  
  15. int directState = 0; // 作
  16. int speed_c = 192;
  17. // PWM, INA, INB LED接
  18. int PWMA = 13;
  19. int INA1 = 12;
  20. int INA2 = 14;
  21. int STBY = 27;
  22. int INB1 = 25;
  23. int INB2 = 26;
  24. int PWMB = 33;
  25. const int ledPin = 2;
  26.  
  27. const int freq = 10000;
  28. const int resolution = 8;
  29.  
  30.  
  31.  
  32. // 定 callbacks onConnect & onDisconnect函
  33. class MyServerCallbacks: public BLEServerCallbacks {
  34.   void onConnect(BLEServer* pServer) {
  35.     deviceCOnnected= true;
  36.   };
  37.   void onDisconnect(BLEServer* pServer) {
  38.     deviceCOnnected= false;
  39.   }
  40. };
  41.  
  42. // 定 callback function 收到新的 (from the Android application)
  43. class MyCallbacks: public BLECharacteristicCallbacks {
  44.   void onWrite(BLECharacteristic *pCharacteristic) {
  45.     std::string rxValue = pCharacteristic->getValue();
  46.     BLE_Code="";
  47.     if(rxValue.length() > 0) {
  48.       Serial.print("受料 : ");
  49.       for(int i = 0; i < rxValue.length(); i++) {
  50.         BLE_Code+=rxValue[i];
  51.         Serial.print(rxValue[i]);
  52.       }
  53.       Serial.println();
  54.       BLE_Code.toUpperCase();
  55.       Serial.println(BLE_Code);
  56.         if(BLE_Code.indexOf("GO")!=-1)
  57.         {
  58.           Serial.println("GO");
  59.           directState=1;
  60.         } else if(BLE_Code.indexOf("BACK")!=-1) {
  61.           Serial.println("BACK");
  62.           directState=2;
  63.         } else if(BLE_Code.indexOf("LEFT")!=-1) {
  64.           Serial.println("LEFT");
  65.           directState=3;
  66.         } else if(BLE_Code.indexOf("RIGHT")!=-1) {
  67.           Serial.println("RIGHT");
  68.           directState=4;
  69.         } else if(BLE_Code.indexOf("RELEASE")!=-1) {
  70.           Serial.println("RELEASE");
  71.           directState=5;
  72.         }
  73.         if(BLE_Code.indexOf("192")!=-1)
  74.         {
  75.           speed_c=192;
  76.         } else if(BLE_Code.indexOf("255")!=-1) {
  77.           speed_c=255;
  78.         }
  79.     }
  80.   }
  81. };
  82.  
  83. void setup() {
  84.   Serial.begin(115200);
  85.   pinMode(ledPin, OUTPUT); //定位出
  86.   pinMode(INA1,OUTPUT);
  87.   pinMode(INA2,OUTPUT);
  88.   pinMode(PWMA,OUTPUT);
  89.   pinMode(STBY,OUTPUT);
  90.   pinMode(INB1,OUTPUT);
  91.   pinMode(INB2,OUTPUT);
  92.   pinMode(PWMB,OUTPUT);
  93.   //digital output test
  94.   digitalWrite(INA1,HIGH); //定位HIGH LOW
  95.   digitalWrite(INA2,LOW);
  96.   digitalWrite(PWMA,LOW);
  97.   digitalWrite(STBY,HIGH);
  98.   digitalWrite(INB1,HIGH);
  99.   digitalWrite(INB2,LOW);
  100.   digitalWrite(PWMB,LOW);
  101.   delay(1000);
  102.  
  103.   //analog output(PWM) test 定LED Channel PWM 率
  104.   ledcSetup(0, freq, resolution);
  105.   ledcSetup(1, freq, resolution);
  106.   ledcSetup(2, freq, resolution);
  107.   ledcSetup(3, freq, resolution);
  108.   ledcSetup(4, freq, resolution);
  109.   ledcSetup(5, freq, resolution);
  110.   ledcSetup(6, freq, resolution);
  111.   //定位Channel
  112.   ledcAttachPin(INA1, 0);
  113.   ledcAttachPin(INA2, 1);
  114.   ledcAttachPin(PWMA, 2);
  115.   ledcAttachPin(STBY, 3);
  116.   ledcAttachPin(INB1, 4);
  117.   ledcAttachPin(INB2, 5);
  118.   ledcAttachPin(PWMB, 6);
  119.   
  120.   // 建立BLE Device
  121.   BLEDevice::init("ESP32_WeMos1");
  122.  
  123.   // 立BLE Server
  124.   BLEServer *perver = BLEDevice::createServer();
  125.   pServer->setCallbacks(new MyServerCallbacks());
  126.  
  127.   // BLE Service
  128.   BLEService *pService = pServer->createService(SERVICE_UUID);
  129.  
  130.   // 建BLE Characteristic
  131.   pCharacteristic = pService->createCharacteristic(
  132.                       CHARACTERISTIC_UUID_TX,
  133.                       BLECharacteristic::PROPERTY_NOTIFY);                     
  134. //  pCharacteristic->addDescriptor(new BLE2902());
  135.   BLECharacteristic *pCharacteristic = pService->createCharacteristic(
  136.                                          CHARACTERISTIC_UUID_RX,
  137.                                          BLECharacteristic::PROPERTY_WRITE);
  138. pCharacteristic->setCallbacks(new MyCallbacks());
  139.  
  140.   // 最先(起)service
  141.   pService->start();
  142.  
  143.   // 起(起)advertising
  144.   pServer->getAdvertising()->start();
  145.   Serial.println("期待BLE手....");
  146.   
  147.   digitalWrite(ledPin,LOW);
  148.   delay(500);
  149.   digitalWrite(ledPin,HIGH);
  150.   delay(500);
  151.   digitalWrite(ledPin,LOW);
  152. }
  153.  
  154. void loop() {
  155.     // Check received message and control output accordingly
  156.     if (directState==1){
  157.         move(speed_c, 1); // full speed, go
  158.         Serial.println("步");
  159.     } else if(directState==2) {
  160.         move(speed_c, 2); // full speed, down
  161.         Serial.println("撤退退");
  162.     } else if(directState==3) {
  163.         move(speed_c, 3); // full speed, left
  164.         Serial.println("左");
  165.     } else if(directState==4) {
  166.         move(speed_c, 4); // full speed, right
  167.         Serial.println("右");
  168.     } else if(directState==5) {
  169.       stop(); //stop
  170.       Serial.println("stop");
  171.     }
  172.   delay(100); //go for 1 second
  173. }
  174.  
  175. void move( int speed, int direction){
  176. //Move specific motor at speed and direction
  177. //speed: 0 is off, and 255 is full speed
  178. //direction: 0 clockwise, 1 counter-clockwise
  179.  
  180.   ledcWrite(3, 255); //STBY disable standby
  181.   Serial.println(direction);
  182.   if(direction == 1){
  183.     //定1正
  184.     ledcWrite(0, 255); //INA1
  185.     ledcWrite(1, 0);   //INA2
  186.     ledcWrite(2, speed);   //PWMA
  187.     //定2正
  188.     ledcWrite(4, 255); //INB1
  189.     ledcWrite(5, 0); //INB2
  190.     ledcWrite(6, speed);   //PWMB
  191.     digitalWrite(ledPin,HIGH);
  192.     delay(500);
  193.     digitalWrite(ledPin,LOW);
  194.   } else if (direction == 2){
  195.     //定1反
  196.     ledcWrite(0, 0);   //INA1
  197.     ledcWrite(1, 255); //INA2
  198.     ledcWrite(2, speed);   //PWMA
  199.     //定2反
  200.     ledcWrite(4, 0);   //INB1
  201.     ledcWrite(5, 255); //INB2
  202.     ledcWrite(6, speed)   //PWMB
  203.     digitalWrite(ledPin,HIGH);
  204.     delay(500);
  205.     digitalWrite(ledPin,LOW);
  206.   } else if (direction == 3){
  207.     //定1正
  208.     ledcWrite(0, 255); //INA1
  209.     ledcWrite(1, 0);   //INA2
  210.     ledcWrite(2, speed);   //PWMA
  211.     //定2反
  212.     ledcWrite(4, 0);   //INB1
  213.     ledcWrite(5, 255); //INB2
  214.     ledcWrite(6, speed);   //PWMB
  215.     digitalWrite(ledPin,HIGH);
  216.     delay(500);
  217.     digitalWrite(ledPin,LOW);
  218.   } else if (direction == 4){
  219.     //定1反
  220.     ledcWrite(0, 0);   //INA1
  221.     ledcWrite(1, 255); //INA2
  222.     ledcWrite(2, speed);   //PWMA
  223.     //定2正
  224.     ledcWrite(4, 255); //INB1
  225.     ledcWrite(5, 0); //INB2
  226.     ledcWrite(6, speed);   //PWMB
  227.     digitalWrite(ledPin,HIGH);
  228.     delay(500);
  229.     digitalWrite(ledPin,LOW);
  230.   }
  231.   Serial.println(speed);
  232. }
  233.  
  234. void stop(){
  235. //enable standby  
  236.   ledcWrite(3, 0); //STBY enable standby
  237.   //Serial.println("stop");
  238. }


 

3.png

4.png

5.png

6.png

7.png





ARDUINO 程式
 站架ESP32_BLE_car_20200713.rar (2.12 KB, 下次: 0, 售: 10 金T)

ANDROID APK案
 BluetoothControl_2020071301.rar (1.95 MB, 下次: 2, 售: 10 金T)
文章出:,站架 ,路行,化,SEO - NetYea



文章出自:

台: joyceigwv3
人(30) | 回(0)| 推 (0)| 收藏 (0)|
全站分: 文活(、展、舞蹈、表演) | 人分: NetYea |
此分下一篇:ETH 上的 如何用Mutichains到Arbit
此分上一篇:址若何http自https

是 (若未登入"人新台"看不到回覆唷!)
* 入:
入片中算式的果(可能0) 
(有*必填)
站台人
  • 累人:162
  • 日人:4
Kaza
目前有料
TOP
全文
ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86