TinkerCAD Ardunio代码错误参数太少

问题描述

我正在为我的课堂建造一个机器人,我们必须有2个伺服器和1个直流电动机以特定方式工作。一切都与arduino uno相连,我的代码可以正常工作,但是我使用tinkercad进行了一些测试,但是遇到一个错误,该错误使我的代码无法在tinker cad中运行,我全然不知所措。

错误

In function 'void loop()': 
44:9: error: too few arguments to function 'void motor(char,char)' 
17:6: note: declared here 
exit status 1

CODE

#include <Servo.h>   // set servo header to let ardduino know you intend to use a servo

Servo mycontinuousservo;      // declare servos to be used
Servo mydegreeservo;

int In1 = 7;        // declare your global variables to indicate pin numbers
int In2 = 8;
int pin = 6;
int servocontinuouspin = 10;
int servodegreepin = 9;
int angle = 90;

void servopos();
void servocontinous();
void motor(char Speed,char Direction);


void setup() {
  
  // put your setup code here,to run once:

  pinMode(In1,OUTPUT);
  pinMode(In2,OUTPUT);
  pinMode(pin,OUTPUT);

  digitalWrite(In1,HIGH);  //pin 7 moves forward
  digitalWrite(In2,LOW);   //pin 8 moves forward

  analogWrite(pin,0);      // start  at 0
  pinMode(servocontinuouspin,OUTPUT);
  pinMode(servodegreepin,OUTPUT);
  mycontinuousservo.attach(servocontinuouspin);
  mydegreeservo.attach(servodegreepin);
  mycontinuousservo.write(90);

  Serial.begin(9600); // for serial communication
}
void loop() {
  
  servocontinous(); //call by ref aforedeclared functions
  servopos();
  motor();

}

// EXIT THE LOOP

void servopos() {         //position function
  int degree = 0;
  int i = 0;
  for (i = 0; i < 18; i++) {
    mydegreeservo.write(degree);
    delay(500); //delay 0.5 seconds
    degree = degree + 10;
  }

}

void servocontinous()    // continous servo settings
{
  for (int angle = 90; angle >= 0; angle--) {
    mycontinuousservo.write(angle);
    delay(50);
  }
  if (angle == 0) {
    Serial.print("speed\n");
  }
  for (angle = 0; angle < 90; angle++)
  {
    mycontinuousservo.write(angle);
    delay(50);
  }

}

void motor()            //motor function
{
  char Speed = 0;
  char Direction = 0;

  if (Serial.available() > 0)          //initialising
  {
    if (Direction == 'f')            //70 representing F on the ASCII table
    {
      delay(500);
      Serial.println("F");
    }
    if (Direction == 'r')
    {
      delay(500);
      Serial.println("R");
    }
  }
  if (Serial.available() > 0)
  {
    Speed = Serial.read();

    if (Speed == '0')
    {
      Speed = 0;
      Serial.println("Speed 0");
    }
    if (Speed == '1')
    {
      Speed = 14;
      Serial.println("Speed 1");
    }
    if (Speed == '2')
    {
      Speed = 29;
      Serial.println("Speed 2");
    }
    if (Speed == '3')
    {
      Speed = 42;
      Serial.println("Speed 3");
    }
    if (Speed == '4')
    {
      Speed = 56;
      Serial.println("Speed 4");
    }
    if (Speed == '5')
    {
      Speed = 70;
      Serial.println("Speed 5");
    }
    if (Speed == '6')
    {
      Speed = 84;
      Serial.println("Speed 6");
    }
    if (Speed == '7')
    {
      Speed = 98;
      Serial.println("Speed 7");
    }
    if (Speed == '8')
    {
      Speed = 112;
      Serial.println("Speed 8");
    }
    if (Speed == '9')
    {
      Speed = 128;
      Serial.println("Speed 9");
    }
  }  delay(5000);
  analogWrite(pin,Speed);
  if (Direction == 'f')
  { digitalWrite(In1,HIGH);
    digitalWrite(In2,LOW);
  } if (Direction == 'r')
  {
    digitalWrite(In1,LOW);
    digitalWrite(In2,HIGH);
  }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)