📜  arduino 不工作直流电机 - C 编程语言代码示例

📅  最后修改于: 2022-03-11 15:04:38.778000             🧑  作者: Mango

代码示例1
AF_DCMotor motor(1);

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Motor test!");

  // turn on motor
  motor.setSpeed(200);

  motor.run(RELEASE);
}

void loop() {
  uint8_t i;

  Serial.print("tick");

  motor.run(FORWARD);
  for (i=0; i<255; i++) {
    motor.setSpeed(i);  
    delay(10);
 }

  for (i=255; i!=0; i--) {
    motor.setSpeed(i);  
    delay(10);
 }

  Serial.print("tock");

  motor.run(BACKWARD);
  for (i=0; i<255; i++) {
    motor.setSpeed(i);  
    delay(10);
 }

  for (i=255; i!=0; i--) {
    motor.setSpeed(i);  
    delay(10);
 }


  Serial.print("tech");
  motor.run(RELEASE);
  delay(1000);
}