PCA9685控制8路SG90舵机实现四足机器人行走

四足机器人外观和结构

PCA9685控制8路SG90舵机实现四足机器人行走_第1张图片

前进代码
  /* USER CODE BEGIN 2 */
    printf("INIT begin\n");
    PCA9685_Go();
    SetPWMFreq(50);
    printf("INIT\n");
    SetPWM(0, 0, SERVO045);
            SetPWM(1, 0, SERVO135);
            SetPWM(2, 0, SERVOMIN);
            SetPWM(3, 0, SERVOMAX);

            SetPWM(4, 0, SERVOMAX);
            SetPWM(5, 0, SERVOMAX);
            SetPWM(6, 0, SERVOMIN);
            SetPWM(7, 0, SERVOMIN);
            HAL_Delay(1000);
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
            SetPWM(7, 0, SERVO090);
            SetPWM(0, 0, SERVOMIN);
            SetPWM(3, 0, SERVO135);
            SetPWM(5, 0, SERVO090);
            SetPWM(1, 0, SERVOMAX);
            SetPWM(2, 0, SERVO045);
            HAL_Delay(1000);
            SetPWM(7, 0, SERVOMIN);
            SetPWM(5, 0, SERVOMAX);
            HAL_Delay(1000);

            SetPWM(4, 0, SERVO045);
            SetPWM(0, 0, SERVO045);
            SetPWM(3, 0, SERVOMAX);
            SetPWM(6, 0, SERVO045);
            SetPWM(2, 0, SERVOMIN);
            SetPWM(1, 0, SERVO135);
            HAL_Delay(1000);
            SetPWM(4, 0, SERVOMAX);
            SetPWM(6, 0, SERVOMIN);
            HAL_Delay(1000);
  }
  /* USER CODE END 3 */

你可能感兴趣的:(物联网系统,STM32)