查看: 1721|回复: 0

【转载】用Blynk控制带有M5Atom的小型双足机器人

[复制链接]

该用户从未签到

发表于 2020-10-13 15:18 | 显示全部楼层 |阅读模式
   我使用M5Atom Matrix(这是M5Stack系列中最小的M5Atom系列)制造了一个双足步行机器人。
NX13_19.jpeg

2.构成组件

1)M5Atom

2)FITEC FS90舵机 x6

3)电池x3
NX13_04.jpg

该结构是使用Fusion 360设计的。

NX13_02.jpg NX13_03.jpg


3.组装
在组装时,很难推入舵机接线。橡胶粘贴在脚底上以防止打滑。
NX13_06.jpg NX13_07.jpg NX13_08.jpg

  1. #include "M5Atom.h"
  2. #include "BluetoothSerial.h" //BluetoothSerial

  3. BluetoothSerial SerialBT;

  4. const uint8_t Srv0 = 22; //GPIO Right Arm
  5. const uint8_t Srv1 = 19; //GPIO Right Leg
  6. const uint8_t Srv2 = 23; //GPIO Right Foot
  7. const uint8_t Srv3 = 33; //GPIO Left Foot
  8. const uint8_t Srv4 = 25; //GPIO Left Leg
  9. const uint8_t Srv5 = 21; //GPIO Left Arm

  10. const uint8_t srv_CH0 = 0, srv_CH1 = 1, srv_CH2 = 2, srv_CH3 = 3, srv_CH4 = 4, srv_CH5 = 5; //チャンネル
  11. const double PWM_Hz = 50;   //PWM频率
  12. const uint8_t PWM_level = 16; //PWM 16bit(0~65535)

  13. int pulseMIN = 1640;  //0deg 500μsec 50Hz 16bit
  14. int pulseMAX = 8190;  //180deg 2500μsec 50Hz 16bit

  15. int cont_min = 0;
  16. int cont_max = 180;

  17. int angZero[] = {90, 78, 85, 88, 92, 90};
  18. int ang0[6];
  19. int ang1[6];
  20. int ang_b[6];
  21. char ang_c[6];
  22. int ts=300;
  23. int td=20;

  24. bool IMU6886Flag = false;  //

  25. // Forward Step
  26. int f_s[19][6]={
  27.   {0,0,0,0,0,0},
  28.   {0,0,-15,-10,0,0},
  29.   {0,0,-15,-15,0,0},
  30.   {-20,15,-15,-15,15,-20},
  31.   {-20,15,0,0,15,-20},
  32.   {-20,15,10,15,15,-20},
  33.   {-20,15,15,15,15,-20},
  34.   {0,0,15,15,0,0},
  35.   {20,-15,15,15,-15,20},
  36.   {20,-15,0,0,-15,20},
  37.   {20,-15,-15,-10,-15,20},
  38.   {20,-15,-15,-15,-15,20},
  39.   {0,0,-15,-15,0,0},
  40.   {-20,15,-15,-15,15,-20},
  41.   {-20,15,0,0,15,-20},
  42.   {-20,15,10,15,15,-20},
  43.   {-20,15,15,15,15,-20},
  44.   {0,0,15,15,0,0}};

  45. int b_s[19][6]={
  46.   {0,0,0,0,0,0},
  47.   {0,0,-15,-10,0,0},
  48.   {0,0,-15,-15,0,0},
  49.   {20,-15,-15,-15,-15,20},
  50.   {20,-15,0,0,-15,20},
  51.   {20,-15,10,15,-15,20},
  52.   {20,-15,15,15,-15,20},
  53.   {0,0,15,15,0,0},
  54.   {-20,15,15,15,15,-20},
  55.   {-20,15,0,0,15,-20},
  56.   {-20,15,-15,-10,15,-20},
  57.   {-20,15,-15,-15,15,-20},
  58.   {0,0,-15,-15,0,0},
  59.   {20,-15,-15,-15,-15,20},
  60.   {20,-15,0,0,-15,20},
  61.   {20,-15,10,15,-15,20},
  62.   {20,-15,15,15,-15,20},
  63.   {0,0,15,15,0,0}};

  64. int l_s[9][6]={
  65.   {0,0,0,0,0,0},
  66.   {0,0,10,15,0,0},
  67.   {0,0,15,15,0,0},
  68.   {-20,15,15,15,-15,-20},
  69.   {-20,15,0,0,-15,-20},
  70.   {-20,15,-15,-10,-15,-20},
  71.   {-20,15,-15,-15,-15,-20},
  72.   {0,0,-15,-15,0,0},
  73.   {0,0,0,0,0,0}};

  74. int r_s[9][6]={
  75.   {0,0,0,0,0,0},
  76.   {0,0,-15,-10,0,0},
  77.   {0,0,-15,-15,0,0},
  78.   {-20,15,-15,-15,-15,-20},
  79.   {-20,15,0,0,-15,-20},
  80.   {-20,15,10,15,-15,-20},
  81.   {-20,15,15,15,-15,-20},
  82.   {0,0,15,15,0,0},
  83.   {0,0,0,0,0,0}};

  84. int r_a[7][6]={
  85.   {0,0,0,0,0,0},
  86.   {80,0,0,0,0,0},
  87.   {0,0,0,0,0,0},
  88.   {80,0,0,0,0,0},
  89.   {0,0,0,0,0,0},
  90.   {80,0,0,0,0,0},
  91.   {0,0,0,0,0,0}};

  92. int l_a[7][6]={
  93.   {0,0,0,0,0,0},
  94.   {0,0,0,0,0,-80},
  95.   {0,0,0,0,0,0},
  96.   {0,0,0,0,0,-80},
  97.   {0,0,0,0,0,0},
  98.   {0,0,0,0,0,-80},
  99.   {0,0,0,0,0,0}};

  100. int delection = 0;

  101. void Initial_Value(){  //initial servo angle
  102.   for (int j=0; j <=5 ; j++){
  103.       ang0[j] = angZero[j];
  104.   }
  105.   for (int j=0; j <=5 ; j++){
  106.       ang1[j] = angZero[j];
  107.   }
  108.   servo_set();
  109. }

  110. void face_clear(){
  111.   for(int i=0; i<25; i++){
  112.     M5.dis.drawpix(i, 0x000000); //black
  113.     //M5.dis.drawpix(i, 0xa5ff00); //orange
  114.   }
  115. }

  116. void face_center(){
  117.   M5.dis.drawpix(6, 0x00ff00);  //red
  118.   M5.dis.drawpix(7, 0x00ff00);
  119.   M5.dis.drawpix(8, 0x00ff00);
  120.   M5.dis.drawpix(16, 0x0000ff);  //blue 0x0000ff
  121.   M5.dis.drawpix(18, 0x0000ff);
  122. }

  123. void Srv_drive(int srv_CH,int SrvAng){
  124.   SrvAng = map(SrvAng, cont_min, cont_max, pulseMIN, pulseMAX);
  125.   ledcWrite(srv_CH, SrvAng);
  126. }

  127. void rs_gets_3c(char gtc[4])
  128. {
  129.   char gc;
  130.   int i;

  131.     sprintf(gtc,"    ");
  132.     for( i = 0 ; i < 4 ; i++ )
  133.     {
  134.       gc = SerialBT.read();
  135.       if (gc == ',')
  136.         break;
  137.       else
  138.         gtc[i] = gc;
  139.     }
  140. }

  141. void forward_step()
  142. {
  143.   for (int i=0; i <=18 ; i++){
  144.     for (int j=0; j <=5 ; j++){
  145.       ang1[j] = angZero[j] + f_s[i][j];
  146.     }
  147.   servo_set();
  148.   }
  149. }

  150. void back_step()
  151. {
  152.   for (int i=0; i <=18 ; i++){
  153.     for (int j=0; j <=5 ; j++){
  154.       ang1[j] = angZero[j] + b_s[i][j];
  155.     }
  156.   servo_set();
  157.   }
  158. }

  159. void right_step()
  160. {
  161.   for (int i=0; i <=8 ; i++){
  162.     for (int j=0; j <=5 ; j++){
  163.       ang1[j] = angZero[j] + r_s[i][j];
  164.     }
  165.   servo_set();
  166.   }
  167. }

  168. void left_step()
  169. {
  170.   for (int i=0; i <=8 ; i++){
  171.     for (int j=0; j <=5 ; j++){
  172.       ang1[j] = angZero[j] + l_s[i][j];
  173.     }
  174.   servo_set();
  175.   }
  176. }

  177. void right_arm()
  178. {
  179.   for (int i=0; i <=6 ; i++){
  180.     for (int j=0; j <=5 ; j++){
  181.       ang1[j] = angZero[j] + r_a[i][j];
  182.     }
  183.   servo_set();
  184.   }
  185. }

  186. void left_arm()
  187. {
  188.   for (int i=0; i <=6 ; i++){
  189.     for (int j=0; j <=5 ; j++){
  190.       ang1[j] = angZero[j] + l_a[i][j];
  191.     }
  192.   servo_set();
  193.   }
  194. }

  195. void servo_set(){
  196.   int a[6],b[6];
  197.   
  198.   for (int j=0; j <=5 ; j++){
  199.       a[j] = ang1[j] - ang0[j];
  200.       b[j] = ang0[j];
  201.       ang0[j] = ang1[j];
  202.   }

  203.   for (int k=0; k <=td ; k++){

  204.       Srv_drive(srv_CH0, a[0]*k/td+b[0]);
  205.       Srv_drive(srv_CH1, a[1]*k/td+b[1]);
  206.       Srv_drive(srv_CH2, a[2]*k/td+b[2]);
  207.       Srv_drive(srv_CH3, a[3]*k/td+b[3]);
  208.       Srv_drive(srv_CH4, a[4]*k/td+b[4]);
  209.       Srv_drive(srv_CH5, a[5]*k/td+b[5]);

  210.       delay(ts/td);
  211.   }
  212. }

  213. void setup() {
  214.   // void M5Atom::begin(bool SerialEnable , bool I2CEnable , bool DisplayEnable )
  215.   M5.begin(true, false, true);
  216.   Serial.begin(151200);
  217.   SerialBT.begin("M5Atom");

  218.   pinMode(Srv0, OUTPUT);
  219.   pinMode(Srv1, OUTPUT);
  220.   pinMode(Srv2, OUTPUT);
  221.   pinMode(Srv3, OUTPUT);
  222.   pinMode(Srv4, OUTPUT);
  223.   pinMode(Srv5, OUTPUT);
  224.   
  225.   //电机PWM通道和频率设置
  226.   ledcSetup(srv_CH0, PWM_Hz, PWM_level);
  227.   ledcSetup(srv_CH1, PWM_Hz, PWM_level);
  228.   ledcSetup(srv_CH2, PWM_Hz, PWM_level);
  229.   ledcSetup(srv_CH3, PWM_Hz, PWM_level);
  230.   ledcSetup(srv_CH4, PWM_Hz, PWM_level);
  231.   ledcSetup(srv_CH5, PWM_Hz, PWM_level);

  232.   //电机引脚和通道设置
  233.   ledcAttachPin(Srv0, srv_CH0);
  234.   ledcAttachPin(Srv1, srv_CH1);
  235.   ledcAttachPin(Srv2, srv_CH2);
  236.   ledcAttachPin(Srv3, srv_CH3);
  237.   ledcAttachPin(Srv4, srv_CH4);
  238.   ledcAttachPin(Srv5, srv_CH5);

  239.   face_clear();
  240.   face_center();

  241.   Initial_Value();
  242. }

  243. void loop() {
  244.   M5.update();
  245.   if ( M5.Btn.wasReleased() ) {
  246.     Initial_Value();
  247.   }
  248.   
  249.   if(SerialBT.available()){
  250.     delection = SerialBT.read();
  251.     switch (delection) {
  252.       case 70: // F FWD
  253.         SerialBT.println("FWD") ;
  254.         forward_step();
  255.       break;
  256.       case 76: // L LEFT
  257.         SerialBT.println("LEFT") ;
  258.         left_step();
  259.       break;
  260.       case 82: // R Right
  261.         SerialBT.println("RIGHT") ;
  262.         right_step();
  263.       break;
  264.       case 66: // B Back
  265.         SerialBT.println("BACK") ;
  266.         back_step();
  267.       break;
  268.       case 72: // H Left Arm
  269.         SerialBT.println("LEFT_Arm") ;
  270.         left_arm();
  271.       break;
  272.       case 77: // M Right Arm
  273.         SerialBT.println("RIGHT_Arm") ;
  274.         right_arm();
  275.       break;
  276.       case 68: //Data
  277.         SerialBT.println("DATA") ;
  278.         for (int i=0; i <=5; i++){
  279.           rs_gets_3c(ang_c);
  280.           ang_b[i] = atoi(ang_c);
  281.           if ((ang_b[i] >= 0) && (ang_b[i] <=180))
  282.             {
  283.               ang0[i] = ang1[i];
  284.               ang1[i] = ang_b[i];
  285.             }
  286.         }
  287.         servo_set();
  288.       break;
  289.     }
  290.   }
  291. }
复制代码

现在我已经创建了动作,但是这次我尝试使用Blynk在iPhone上对其进行控制
NX13_26.jpg
Blynk按钮控制前进,后退,右转,左转,右手向上和左手向上。
NX13_27.png
NX13_28.png

  1. #define BLYNK_PRINT Serial
  2. #define BLYNK_USE_DIRECT_CONNECT

  3. #include "M5Atom.h"
  4. #include <BlynkSimpleEsp32_BLE.h>
  5. #include <BLEDevice.h>
  6. #include <BLEServer.h>

  7. char auth[] = "XXXXXXXXXXXXXXXXXXXXXXXX";  //通过电子邮件发送的身份验证令牌
  8. const uint8_t Srv0 = 22; //GPIO Right Arm
  9. const uint8_t Srv1 = 19; //GPIO Right Leg
  10. const uint8_t Srv2 = 23; //GPIO Right Foot
  11. const uint8_t Srv3 = 33; //GPIO Left Foot
  12. const uint8_t Srv4 = 25; //GPIO Left Leg
  13. const uint8_t Srv5 = 21; //GPIO Left Arm

  14. const uint8_t srv_CH0 = 0, srv_CH1 = 1, srv_CH2 = 2, srv_CH3 = 3, srv_CH4 = 4, srv_CH5 = 5; //チャンネル
  15. const double PWM_Hz = 50;   //PWM频率
  16. const uint8_t PWM_level = 16; //PWM 16bit(0~65535)

  17. int pulseMIN = 1640;  //0deg 500μsec 50Hz 16bit
  18. int pulseMAX = 8190;  //180deg 2500μsec 50Hz 16bit

  19. int cont_min = 0;
  20. int cont_max = 180;

  21. int angZero[] = {90, 78, 85, 88, 92, 90};
  22. int ang0[6];
  23. int ang1[6];
  24. int ang_b[6];
  25. char ang_c[6];
  26. int ts=160;
  27. int td=20;

  28. bool IMU6886Flag = false;

  29. // Forward Step
  30. int f_s[19][6]={
  31.   {0,0,0,0,0,0},
  32.   {0,0,-15,-10,0,0},
  33.   {0,0,-15,-15,0,0},
  34.   {-20,15,-15,-15,15,-20},
  35.   {-20,15,0,0,15,-20},
  36.   {-20,15,10,15,15,-20},
  37.   {-20,15,15,15,15,-20},
  38.   {0,0,15,15,0,0},
  39.   {20,-15,15,15,-15,20},
  40.   {20,-15,0,0,-15,20},
  41.   {20,-15,-15,-10,-15,20},
  42.   {20,-15,-15,-15,-15,20},
  43.   {0,0,-15,-15,0,0},
  44.   {-20,15,-15,-15,15,-20},
  45.   {-20,15,0,0,15,-20},
  46.   {-20,15,10,15,15,-20},
  47.   {-20,15,15,15,15,-20},
  48.   {0,0,15,15,0,0},
  49.   {0,0,0,0,0,0}};

  50. int b_s[19][6]={
  51.   {0,0,0,0,0,0},
  52.   {0,0,-20,-15,0,0},
  53.   {0,0,-15,-15,0,0},
  54.   {0,-15,-15,-15,-15,20},
  55.   {0,-15,0,0,-15,20},
  56.   {0,-15,15,20,-15,20},
  57.   {0,-15,15,15,-15,20},
  58.   {0,0,15,15,0,0},
  59.   {0,15,15,15,15,-20},
  60.   {0,15,0,0,15,-20},
  61.   {0,15,-20,-15,15,-20},
  62.   {0,15,-15,-15,15,-20},
  63.   {0,0,-15,-15,0,0},
  64.   {0,-15,-15,-15,-15,20},
  65.   {0,-15,0,0,-15,20},
  66.   {0,-15,15,20,-15,20},
  67.   {0,-15,15,15,-15,20},
  68.   {0,0,15,15,0,0},
  69.   {0,0,0,0,0,0}};

  70. int l_s[9][6]={
  71.   {0,0,0,0,0,0},
  72.   {0,0,10,15,0,0},
  73.   {0,0,15,15,0,0},
  74.   {-20,15,15,15,-15,-20},
  75.   {-20,15,0,0,-15,-20},
  76.   {-20,15,-15,-10,-15,-20},
  77.   {-20,15,-15,-15,-15,-20},
  78.   {0,0,-15,-15,0,0},
  79.   {0,0,0,0,0,0}};

  80. int r_s[9][6]={
  81.   {0,0,0,0,0,0},
  82.   {0,0,-15,-10,0,0},
  83.   {0,0,-15,-15,0,0},
  84.   {-20,15,-15,-15,-15,-20},
  85.   {-20,15,0,0,-15,-20},
  86.   {-20,15,10,15,-15,-20},
  87.   {-20,15,15,15,-15,-20},
  88.   {0,0,15,15,0,0},
  89.   {0,0,0,0,0,0}};

  90. int r_a[7][6]={
  91.   {0,0,0,0,0,0},
  92.   {80,0,0,0,0,0},
  93.   {0,0,0,0,0,0},
  94.   {80,0,0,0,0,0},
  95.   {0,0,0,0,0,0},
  96.   {80,0,0,0,0,0},
  97.   {0,0,0,0,0,0}};

  98. int l_a[7][6]={
  99.   {0,0,0,0,0,0},
  100.   {0,0,0,0,0,-80},
  101.   {0,0,0,0,0,0},
  102.   {0,0,0,0,0,-80},
  103.   {0,0,0,0,0,0},
  104.   {0,0,0,0,0,-80},
  105.   {0,0,0,0,0,0}};

  106. int delection = 0;

  107. void Initial_Value(){  //initial servo angle
  108.   for (int j=0; j <=5 ; j++){
  109.       ang0[j] = angZero[j];
  110.   }
  111.   for (int j=0; j <=5 ; j++){
  112.       ang1[j] = angZero[j];
  113.   }
  114.   servo_set();
  115. }

  116. void face_clear(){
  117.   for(int i=0; i<25; i++){
  118.     M5.dis.drawpix(i, 0x000000); //black
  119.     //M5.dis.drawpix(i, 0xa5ff00); //orange
  120.   }
  121. }

  122. void face_center(){
  123.   M5.dis.drawpix(6, 0x00ff00);  //red
  124.   M5.dis.drawpix(7, 0x00ff00);
  125.   M5.dis.drawpix(8, 0x00ff00);
  126.   M5.dis.drawpix(16, 0x0000ff);  //blue 0x0000ff
  127.   M5.dis.drawpix(18, 0x0000ff);
  128. }

  129. void face_right(){
  130.   face_clear();
  131.   M5.dis.drawpix(7, 0x00ff00);
  132.   M5.dis.drawpix(8, 0x00ff00);
  133.   M5.dis.drawpix(9, 0x00ff00);
  134.   M5.dis.drawpix(17, 0x0000ff);
  135.   M5.dis.drawpix(19, 0x0000ff);
  136. }

  137. void face_left(){
  138.   face_clear();
  139.   M5.dis.drawpix(5, 0x00ff00);
  140.   M5.dis.drawpix(6, 0x00ff00);
  141.   M5.dis.drawpix(7, 0x00ff00);
  142.   M5.dis.drawpix(15, 0x0000ff);
  143.   M5.dis.drawpix(17, 0x0000ff);
  144. }

  145. void Srv_drive(int srv_CH,int SrvAng){
  146.   SrvAng = map(SrvAng, cont_min, cont_max, pulseMIN, pulseMAX);
  147.   ledcWrite(srv_CH, SrvAng);
  148. }

  149. void forward_step()
  150. {
  151.   for (int i=0; i <=18 ; i++){
  152.     for (int j=0; j <=5 ; j++){
  153.       ang1[j] = angZero[j] + f_s[i][j];
  154.     }
  155.   servo_set();
  156.   }
  157.   delection = 0;
  158. }

  159. void back_step()
  160. {
  161.   for (int i=0; i <=18 ; i++){
  162.     for (int j=0; j <=5 ; j++){
  163.       ang1[j] = angZero[j] + b_s[i][j];
  164.     }
  165.   servo_set();
  166.   }
  167.   delection = 0;
  168. }

  169. void right_step()
  170. {
  171.   face_right();
  172.   for (int i=0; i <=8 ; i++){
  173.     for (int j=0; j <=5 ; j++){
  174.       ang1[j] = angZero[j] + r_s[i][j];
  175.     }
  176.   servo_set();
  177.   }
  178.   face_clear();
  179.   face_center();
  180.   delection = 0;
  181. }

  182. void left_step()
  183. {
  184.   face_left();
  185.   for (int i=0; i <=8 ; i++){
  186.     for (int j=0; j <=5 ; j++){
  187.       ang1[j] = angZero[j] + l_s[i][j];
  188.     }
  189.   servo_set();
  190.   }
  191.   face_clear();
  192.   face_center();
  193.   delection = 0;
  194. }

  195. void right_arm()
  196. {
  197.   face_right();
  198.   for (int i=0; i <=6 ; i++){
  199.     for (int j=0; j <=5 ; j++){
  200.       ang1[j] = angZero[j] + r_a[i][j];
  201.     }
  202.   servo_set();
  203.   }
  204.   face_clear();
  205.   face_center();
  206.   delection = 0;
  207. }

  208. void left_arm()
  209. {
  210.   face_left();
  211.   for (int i=0; i <=6 ; i++){
  212.     for (int j=0; j <=5 ; j++){
  213.       ang1[j] = angZero[j] + l_a[i][j];
  214.     }
  215.   servo_set();
  216.   }
  217.   face_clear();
  218.   face_center();
  219.   delection = 0;
  220. }

  221. void servo_set(){
  222.   int a[6],b[6];
  223.   
  224.   for (int j=0; j <=5 ; j++){
  225.       a[j] = ang1[j] - ang0[j];
  226.       b[j] = ang0[j];
  227.       ang0[j] = ang1[j];
  228.   }

  229.   for (int k=0; k <=td ; k++){

  230.       Srv_drive(srv_CH0, a[0]*k/td+b[0]);
  231.       Srv_drive(srv_CH1, a[1]*k/td+b[1]);
  232.       Srv_drive(srv_CH2, a[2]*k/td+b[2]);
  233.       Srv_drive(srv_CH3, a[3]*k/td+b[3]);
  234.       Srv_drive(srv_CH4, a[4]*k/td+b[4]);
  235.       Srv_drive(srv_CH5, a[5]*k/td+b[5]);

  236.       delay(ts/td);
  237.   }
  238. }

  239. BLYNK_WRITE(V0) {
  240.   int x = param.asInt();
  241.   if(x == 1){
  242.     delection = 70;  //forward step
  243.     Serial.println("FWD");
  244.   }
  245. }

  246. BLYNK_WRITE(V1) {
  247.   int x = param.asInt();
  248.   if(x == 1){
  249.     delection = 66;  //Back step
  250.     Serial.println("BACK");
  251.   }
  252. }

  253. BLYNK_WRITE(V2) {
  254.   int x = param.asInt();
  255.   if(x == 1){
  256.     delection = 82;  //Right step
  257.     Serial.println("RIGHT STEP");
  258.   }
  259. }

  260. BLYNK_WRITE(V3) {
  261.   int x = param.asInt();
  262.   if(x == 1){
  263.     delection = 76;  //Left step
  264.     Serial.println("LEFT STEP");
  265.   }
  266. }

  267. BLYNK_WRITE(V4) {
  268.   int x = param.asInt();
  269.   if(x == 1){
  270.     delection = 77;  //Right Arm
  271.     Serial.println("RIGHT ARM");
  272.   }
  273. }

  274. BLYNK_WRITE(V5) {
  275.   int x = param.asInt();
  276.   if(x == 1){
  277.     delection = 72;  //Left Arm
  278.   Serial.println("LEFT ARM");  
  279.   }
  280. }

  281. void setup() {
  282.   Serial.begin(151200);
  283.   // void M5Atom::begin(bool SerialEnable , bool I2CEnable , bool DisplayEnable )
  284.   M5.begin(true, false, true);

  285.   Blynk.setDeviceName("Blynk");
  286.   Blynk.begin(auth);

  287.   pinMode(Srv0, OUTPUT);
  288.   pinMode(Srv1, OUTPUT);
  289.   pinMode(Srv2, OUTPUT);
  290.   pinMode(Srv3, OUTPUT);
  291.   pinMode(Srv4, OUTPUT);
  292.   pinMode(Srv5, OUTPUT);
  293.   
  294.   //电机PWM通道和频率设置
  295.   ledcSetup(srv_CH0, PWM_Hz, PWM_level);
  296.   ledcSetup(srv_CH1, PWM_Hz, PWM_level);
  297.   ledcSetup(srv_CH2, PWM_Hz, PWM_level);
  298.   ledcSetup(srv_CH3, PWM_Hz, PWM_level);
  299.   ledcSetup(srv_CH4, PWM_Hz, PWM_level);
  300.   ledcSetup(srv_CH5, PWM_Hz, PWM_level);

  301.   //电机引脚和通道设置
  302.   ledcAttachPin(Srv0, srv_CH0);
  303.   ledcAttachPin(Srv1, srv_CH1);
  304.   ledcAttachPin(Srv2, srv_CH2);
  305.   ledcAttachPin(Srv3, srv_CH3);
  306.   ledcAttachPin(Srv4, srv_CH4);
  307.   ledcAttachPin(Srv5, srv_CH5);

  308.   face_center();

  309.   Initial_Value();
  310. }

  311. void loop() {
  312.   M5.update();
  313.   Blynk.run();
  314.   if ( M5.Btn.wasReleased() ) {
  315.     Initial_Value();
  316.   }
  317.   
  318.   switch (delection) {
  319.     case 70: // F FWD
  320.       forward_step();
  321.     break;
  322.     case 76: // L LEFT
  323.       left_step();
  324.     break;
  325.     case 82: // R Right
  326.       right_step();
  327.     break;
  328.     case 66: // B Back
  329.       back_step();
  330.     break;
  331.     case 72: // H Left Arm
  332.       left_arm();
  333.     break;
  334.     case 77: // M Right Arm
  335.       right_arm();
  336.     break;
  337.   }
  338. }
复制代码


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

arduino程序设计基础 blinker物联网解决方案

热门推荐

【教程】pico+hx711电子秤
【教程】pico+hx711电子秤
pico+hx711电子秤 【前言】 我做过多款电子秤,这次移植到pico上
ESP8266+Onenet平台远程数据传输和控制
ESP8266+Onenet平台远程数
这是我的第一个diy,主要功能实现了onenet云平台温湿度数据的传输和远程控制LED灯平台
【Arduino】108种传感器模块系列实验(48)---三轴ADXL345模块
【Arduino】108种传感器模
37款传感器与模块的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是
ps2遥控小车——uno实现
ps2遥控小车——uno实现
前几天在阁楼发现了好久以前3d打印,激光切割的底盘,于是决定做这个东西 正好手上又
震惊!OLED菜单竟只用10行代码就可以完成到完美!!!
震惊!OLED菜单竟只用10行
震惊!OLED菜单竟只用10行代码就可
Copyright   ©2015-2016  Arduino中文社区  Powered by©Discuz!   
快速回复 返回顶部 返回列表